Comments

Discuss and share scripts and script files...
Muroph
Posts: 561
Joined: 21 Aug 2007 15:13

Comments

Postby Muroph » 07 Jun 2009 08:26

here's a useful script.
it emulates the popup menu from the comments column, since apparently it's not accessible anywhere else.
it also adds a few useful commands.
PS: "set last comment" refers to the last comment set using the script.

Code: Select all

"_settings"
   global $sing_multi,$last_file;
   $sing_multi=s; // "s" for single, "m" for multi-line input
   $last_file="%temp%\xy_last_comment.tmp"; // file used to remember the last comment
   
"Edit Comment... : _edit" //use these labels to call the commands directly
   global $label;
   $label = edit;
   sub menu;
"Set Last Comment : _last"
   global $label;
   $label = last;
   sub menu;
"Prepend Comment : _prepend"
   global $label;
   $label = prepend;
   sub menu;
"Append Comment : _append"
   global $label;
   $label = append;
   sub menu;
"Replacer : _replacer"
   global $label;
   $label = replacer;
   sub menu;
"Eraser : _eraser"
   global $label;
   $label = eraser;
   sub menu;
"Copy Comment : _copy"
   global $label;
   $label = copy;
   sub menu;
"Paste Comment : _paste"
   global $label;
   $label = paste;
   sub menu;
"Remove Comment : _remove"
   global $label;
   $label = remove;
   sub menu;

"menu : menu"
   global $label,$clipboard,$crlf,$items,$sing_multi,$last_file;
   $total=getinfo(countselected);
   if($total<1){
      status "Nothing Selected",ffcc00,alert;
      end 1;}
   sub _settings;
   $last=(exists("$last_file")==1)?(readfile("$last_file")):(""); //read last used comment
   strlen $len,$last;
   substr $last,$last,0,20; //trim to 20 chars
   replace $last,$last,"<crlf>","¶"; //replace some dangerous chars
   replace $last,$last,'"',"''"; // “
   replace $last,$last,'&',"ε";
   replace $last,$last,":",":";
   if($len>20){$last=$last.'...';} //add "..." if the string was trimmed
   $cliptemp=<clipboard>; //save clipboard to a temp variable
   strlen $len,$cliptemp;
   substr $clip,$cliptemp,0,20;
   replace $clip,$clip,"<crlf>","¶";
   replace $clip,$clip,'"',"''";
   replace $clip,$clip,'&',"ε";
   replace $clip,$clip,":",":";
   if($len>20){$clip=$clip.'...';}
   substr $itemstemp,report("|{fullname}",1),1;
   $crlf='$crlf';
   $clipboard='$clipboard';
   $items='$items';
   //create the script
   $script=<<<COMMENTSCRIPT
"Edit Comment... : edit"
   global $crlf,$items;
   $comment=gettoken(report("{fullname}|{comment}$crlf"),2,"<focitem>|"); //get comment from focused item
   $comment=gettoken($comment,1,$crlf);
   regexreplace $comment,$comment,"¶",$crlf;
   $comment = input("Enter New Comment",,"$comment",$sing_multi); //enter new comment
   comment $comment,"$items"; //apply comment to selected items
   writefile("$last_file",$comment); //save "last used comment"
"Set Last Comment (''$last'') : last"
   global $items;
   $comment=(exists("$last_file")==1)?(readfile("$last_file")):("");
   comment $comment,"$items";
-
"Prepend Comment : prepend"
   global $crlf;
   $comment=input("Prepend Comment",,(exists("$last_file")==1)?(readfile("$last_file")):(""),$sing_multi);
   $itemlist=report("{fullname}$crlf",1);
   $commlist=report("{comment}$crlf",1);
   $counter=1;
   while($counter<=$total){
      $curitem=gettoken($itemlist,$counter,$crlf);
      $curcomm=gettoken($commlist,$counter,$crlf);
      comment "$comment$curcomm",$curitem;
      $counter++;}
   writefile("$last_file",$comment);
"Append Comment : append"
   global $crlf;
   $comment=input("Append Comment",,(exists("$last_file")==1)?(readfile("$last_file")):(""),$sing_multi);
   $itemlist=report("{fullname}$crlf",1);
   $commlist=report("{comment}$crlf",1);
   $counter=1;
   while($counter<=$total){
      $curitem=gettoken($itemlist,$counter,"$crlf");
      $curcomm=gettoken($commlist,$counter,"$crlf");
      comment "$curcomm$comment",$curitem;
      $counter++;}
   writefile("$last_file",$comment);
"Replacer : replacer"
   global $crlf;
   $old=input("Replace this",,,$sing_multi);
   $new=input("With this",,,$sing_multi);
   $itemlist=report("{fullname}$crlf",1);
   $commlist=report("{comment}$crlf",1);
   $counter=1;
   while($counter<=$total){
      $curitem=gettoken($itemlist,$counter,$crlf);
      $curcomm=gettoken($commlist,$counter,$crlf);
      replace $curcomm,$curcomm,$old,$new;
      comment "$curcomm",$curitem;
      $counter++;}
"Eraser : eraser"
   global $crlf;
   $erase=input("Erase this",,,$sing_multi);
   $itemlist=report("{fullname}$crlf",1);
   $commlist=report("{comment}$crlf",1);
   $counter=1;
   while($counter<=$total){
      $curitem=gettoken($itemlist,$counter,$crlf);
      $curcomm=gettoken($commlist,$counter,$crlf);
      replace $curcomm,$curcomm,$erase,"";
      comment "$curcomm",$curitem;
      $counter++;}
-
"Copy Comment : copy"
   global $crlf,$items;
   $comment=gettoken(report("{fullname}|{comment}$crlf",1),2,"<curitem>|"); //get comment from current item
   $comment=gettoken($comment,1,$crlf);
   regexreplace $comment,$comment,"¶",$crlf;
   if("$comment"!=""){copytext $comment;} //if the comment exists,copy to clipboard
   else{status "Current item doesn't have a comment",ffaa00,alert;} //else,print a message
"Paste Comment (''$clip'') : paste"
   global $clipboard,$items;
   comment $clipboard,"$items"; //paste comment from clipboard
   writefile("$last_file",$clipboard);
-
"Remove Comment : remove"
   global $items;
   comment "","$items";
-
"Cancel : cancel"
   end 1;
COMMENTSCRIPT;
   $crlf="<crlf>";
   $clipboard="$cliptemp";
   $items="$itemstemp";
   load $script,($label)?($label):(),s; //load the script
Last edited by Muroph on 16 Sep 2009 01:04, edited 4 times in total.
My shared scripts:
TeraCopy Integration, Tag Manager, Comments Menu, Text Replacer, Image and Media Tools, Checksum Calculator, Video Calculator
only 5 URLs are allowed on the sig...

Muroph
Posts: 561
Joined: 21 Aug 2007 15:13

Re: Comments

Postby Muroph » 10 Jun 2009 07:53

new version

-fixed a few bugs
-default text in "edit comment" now is the focused item's comment.
-found some better character replacements for the menu.


BTW, when writing and testing the script i came across a bug where a global variable would not be unset after the script execution.
it happened more than once, but i accidentally deleted the script that caused it, and i don't know how to reproduce the bug without it.
My shared scripts:
TeraCopy Integration, Tag Manager, Comments Menu, Text Replacer, Image and Media Tools, Checksum Calculator, Video Calculator
only 5 URLs are allowed on the sig...

admin
Site Admin
Posts: 41366
Joined: 22 May 2004 15:48
Location: Cologne, Win 8.1
Contact:

Re: Comments

Postby admin » 10 Jun 2009 07:55

Muroph wrote:BTW, when writing and testing the script i came across a bug where a global variable would not be unset after the script execution.
it happened more than once, but i accidentally deleted the script that caused it, and i don't know how to reproduce the bug without it.
Oh, I'll check that, thanks.

admin
Site Admin
Posts: 41366
Joined: 22 May 2004 15:48
Location: Cologne, Win 8.1
Contact:

Re: Comments

Postby admin » 10 Jun 2009 13:51

admin wrote:
Muroph wrote:BTW, when writing and testing the script i came across a bug where a global variable would not be unset after the script execution.
it happened more than once, but i accidentally deleted the script that caused it, and i don't know how to reproduce the bug without it.
Oh, I'll check that, thanks.

Cannot find anything suspicious in the code. Next time don't delete it. :P

Muroph
Posts: 561
Joined: 21 Aug 2007 15:13

Re: Comments

Postby Muroph » 19 Jun 2009 20:01

new version.

-fixed some bugs (hopefully).
-revised the code.

again i came across something strange while writing the script.
a local variable with no value assigned is treated literally.
but a global variable will be resolved to an empty value.

Code: Select all

msg asd $test fgh;
 $test=1;
 msg asd $test fgh;
 //unset $test;
 //msg asd $test fgh;
 global $test;
 msg asd $test fgh;


and when i uncommented (is this a word?) the 4th and 5th lines in the example, i got this error:

Code: Select all

Error    9 (00000009)
Desc   Subscript out of range
Dll   0
Proc   script_Process

Source   XYplorer
XY ver   8.00.0001
OS   WinXP (Service Pack 2)
Date   19/6/2009 15:55:08
My shared scripts:
TeraCopy Integration, Tag Manager, Comments Menu, Text Replacer, Image and Media Tools, Checksum Calculator, Video Calculator
only 5 URLs are allowed on the sig...

admin
Site Admin
Posts: 41366
Joined: 22 May 2004 15:48
Location: Cologne, Win 8.1
Contact:

Re: Comments

Postby admin » 20 Jun 2009 05:56

Muroph wrote:new version.

-fixed some bugs (hopefully).
-revised the code.

again i came across something strange while writing the script.
a local variable with no value assigned is treated literally.
but a global variable will be resolved to an empty value.

Code: Select all

msg asd $test fgh;
 $test=1;
 msg asd $test fgh;
 //unset $test;
 //msg asd $test fgh;
 global $test;
 msg asd $test fgh;


and when i uncommented (is this a word?) the 4th and 5th lines in the example, i got this error:

Code: Select all

Error    9 (00000009)
Desc   Subscript out of range
Dll   0
Proc   script_Process

Source   XYplorer
XY ver   8.00.0001
OS   WinXP (Service Pack 2)
Date   19/6/2009 15:55:08

1. By declaring a var as global it is initialized to ""
2. Good find, thanks!

Muroph
Posts: 561
Joined: 21 Aug 2007 15:13

Re: Comments

Postby Muroph » 31 Jul 2009 21:34

new version, with a small bug fix.
My shared scripts:
TeraCopy Integration, Tag Manager, Comments Menu, Text Replacer, Image and Media Tools, Checksum Calculator, Video Calculator
only 5 URLs are allowed on the sig...

lukescammell
Posts: 744
Joined: 28 Jul 2006 12:15
Location: Kent, UK
Contact:

Re: Comments

Postby lukescammell » 21 Aug 2009 11:04

This is actually very, very cool - thanks :)
Used to update to the latest beta every day. Now I have children instead…
Windows 10 Pro x64 (everywhere except phone…)

Muroph
Posts: 561
Joined: 21 Aug 2007 15:13

Re: Comments

Postby Muroph » 23 Aug 2009 18:45

fixed a bug: the script could freeze xy when changing a lot of items at once.
My shared scripts:
TeraCopy Integration, Tag Manager, Comments Menu, Text Replacer, Image and Media Tools, Checksum Calculator, Video Calculator
only 5 URLs are allowed on the sig...

Muroph
Posts: 561
Joined: 21 Aug 2007 15:13

Re: Comments

Postby Muroph » 16 Sep 2009 01:04

new version.
recently i've started using comments as secondary tags, so i came up with some nice functions to make the job easier. 8)

what's new:
-"prepend" and "append" comment: insert a new comment before or after (respectively) the comments in all selected items.
-"replacer" and "eraser": replace or quickly erase a string in selected items' comments.
-basic settings: change the temp file location; choose between single and multi-line input dialogs.
My shared scripts:
TeraCopy Integration, Tag Manager, Comments Menu, Text Replacer, Image and Media Tools, Checksum Calculator, Video Calculator
only 5 URLs are allowed on the sig...


Return to “Script Exchange”



Who is online

Users browsing this forum: No registered users and 1 guest