Page 1 of 1

Script Request - Convert Expression to Web-Safe File Names

Posted: 11 Mar 2010 23:18
by SkyFrontier
Can anyone please code something to read clipboard "Script Request - Convert Expression to Web-Safe File Names" and write result "ScriptRequest_-_ConvertExpressionToWebSafeFileNames" back into clipboard, having an .ini file to (previously, hand-made) write search and replacement rules like

é > e
? > G
' > _
" " (blank spaces) > _


and so on...?

Thank you, folks!

Re: Script Request - Convert Expression to Web-Safe File Names

Posted: 12 Mar 2010 00:53
by Stefan
You may try it on your own... it's not that hard:

Code: Select all

"WebSave"
  //*** get clipboard:
  //$clipboard = "<clipboard>"; 

  //*** Test:
  $clipboard = "Script Request - Convert Expression to Web-Safe File Names";
  //***     TO: "ScriptRequest_-_ConvertExpressionToWebSafeFileNames" 

   //*** replace string, search, replacement, [matchcase 0: A=a ----  1: A<>a] 
   $out = replace($clipboard, " - ", "_-_", 1);
   $out = replace($out, " ", "", 1);
   $out = replace($out, "é", "e", 1);

   //*** your replacements:
   //$out = replace($out, "find", "replacement", 1);
   //$out = replace($out, "find", "replacement", 1);
   //$out = replace($out, "find", "replacement", 1);

       //*** Test:
       msg $out;

       //*** set clipboard:
       //copytext $out;  


"Edit this &script : edit"
   self $ScriptFile, file;
   OpenWith Notepad, ,$ScriptFile;
Explanation:
//*** = comments
// = just disabled code

Of course you have to take care to replace in the right order, like here:
  1.) $out = replace($clipboard, " - ", "_-_", 1); first we need the spaces to find the right part
  2.) $out = replace($out, " ", "", 1); after that then we can remove the other blanks.
  If you would first remove all blanks, you couldn't replace " - " by "_-_" afterwards anymore.

Re: Script Request - Convert Expression to Web-Safe File Names

Posted: 12 Mar 2010 01:07
by SkyFrontier
Thanks much, Stefan.
I already tried some scripting stuff and plan to later add them to the forums - but they are just time savers for me, don't know if they can be useful to others. Who knows...?

Anyway, I plan to study XY scripting when doing my personal XY project, New User's Reference Guide. That will be inevitable to me. ^^

That was a link for a beta file, the discussion page can be found here. Well. Nobody's discussing but people are downloading. Hope they find some level of help on what's currently available.

Re: Script Request - Convert Expression to Web-Safe File Names

Posted: 12 Mar 2010 01:26
by SkyFrontier
Script not worked.
It makes sense but won't work, besides giving a useless prompt named "ScriptRequest_-_ConvertExpressionToWebSafeFileNames".
Any ideas...?

Re: Script Request - Convert Expression to Web-Safe File Names

Posted: 12 Mar 2010 01:29
by SkyFrontier
Value "$clipboard =" should read *any* current clipboard text, and it's filled.
Might help...?

Re: Script Request - Convert Expression to Web-Safe File Names

Posted: 12 Mar 2010 10:13
by Stefan
SkyFrontier wrote:Script not worked.
It makes sense but won't work,
besides giving a useless prompt named "ScriptRequest_-_ConvertExpressionToWebSafeFileNames".
Any ideas...?
:mrgreen: O.K., i just expected too much from you, sorry.

This was just an proof-of-concept which worked without doing any harm, just showing it could be done.
But i understood i didn't should do such save things because script-novices doesn't understand this behaviour.


You just have to un-comment some part of the code, and comment-out others, to make the script do what you want.
Here is the script, modified to working as you had expected:

Code: Select all

"WebSave"
  //*** get clipboard:
  $clipboard = "<clipboard>";

  //*** Test:
  //$clipboard = "Script Request - Convert Expression to Web-Safe File Names";
  //***     TO: "ScriptRequest_-_ConvertExpressionToWebSafeFileNames"

   //*** replace string, search, replacement, [matchcase 0: A=a ----  1: A<>a]
   $out = replace($clipboard, " - ", "_-_", 1);
   $out = replace($clipboard, "-", "", 1);
   $out = replace($out, " ", "", 1);
   $out = replace($out, "é", "e", 1);

   //*** your replacements:
   //$out = replace($out, "find", "replacement", 1);
   //$out = replace($out, "find", "replacement", 1);
   //$out = replace($out, "find", "replacement", 1);

       //*** Test:
       //msg $out;

       //*** set clipboard:
       copytext $out; 


"Edit this &script : edit"
   self $ScriptFile, file;
   OpenWith Notepad, ,$ScriptFile;

Re: Script Request - Convert Expression to Web-Safe File Names

Posted: 12 Mar 2010 10:58
by SkyFrontier
Nah, I'm not that dumb. :D
I even took off the

Code: Select all

"Edit this &script : edit"
   self $ScriptFile, file;
   OpenWith Notepad, ,$ScriptFile;
part so the remaining code doesn't work anyway. :mrgreen:

-yes, I'm guilty - I totally forgot the ability to comment when overlooked your code, now

Code: Select all

"WebSave"
  //*** get clipboard:
  $clipboard = "<clipboard>";

   //*** replace string, search, replacement, [matchcase 0: A=a ----  1: A<>a]
   $out = replace($clipboard, "-", "_-_", 1);
   //$out = replace($clipboard, "-", "", 1);
   $out = replace($out, " ", "", 1);
   $out = replace($out, "é", "e", 1);

       //*** set clipboard:
       copytext $out;
fully fits my needs when saving pages to read them offline, sparing me part of the boring task of eliminating blank spaces and replacing "-" with "_". Thanks, Stefan and Don!

-just an idea: wouldn't it be nice to have a Firefox extension that could take advantage of a portable installation of XYplorer, so even the alt+tab between XY/FFox could be eliminated? Can XYplorer act as a command line tool ready to work along 3rd party apps? I think it should be great, due to XY scripting proven flexibility...

Re: Script Request - Convert Expression to Web-Safe File Names

Posted: 12 Mar 2010 11:22
by Stefan
Fine it worked, good work.

Now it's time doing the next step: using regexreplace() instead of replace()


In the meantime i have added some more comments to my first script
not for you but for the other novices:

Code: Select all

/*
XYSName: ModifyClipboardContentToWebsave.xys
Purpose: Modify clipboard content by search and replace actions

Date     Version   Description
20100312 003

Script notes:
Four /'s indicate an line with comments
Two  /'s indicate an commented-out code line
*/


"WebSave modify clipboard content"
////---110--- set var $clipboard with content to do s&r modifications

      //// 111 get clipboard and set var $clipboard to clipboard content:
      $clipboard = "<clipboard>"; 
      
      //// 112 Test, set var $clipboard to an given string for testing:
      //$clipboard = "Script Request - Convert Expression to Web-Safe File Names";
      
      //// 113  the result should look like: 
      ////           "ScriptRequest_-_ConvertExpressionToWebSafeFileNames"



////---120--- search and replace chars in var $clipboard and replace or remove them
      $out = $clipboard;
      ////Syntax: regexreplace(string, pattern, replacement, [matchcase])
      //// 121 your already suggested replacements:
      $out = regexreplace($out, "(\w)-(\w)", "$1$2", 1);
      $out = regexreplace($out, " - ", "_-_", 1);
      $out = regexreplace($out, " ", "", 1);
      $out = regexreplace($out, "é", "e", 1);

      //// 122 your other replacements:
      //// Instead of "findThis" type an char to find,
      //// Instead of "replacementWithThis" type in the replacement or use "" to remove the found
      $out = regexreplace($out, "findThis", "replacementWithThis", 1);
      $out = regexreplace($out, "findThis", "replacementWithThis", 1);
      $out = regexreplace($out, "findThis", "replacementWithThis", 1);


////---190--- Output the result
       //// 191 Test, just show an message box for testing:
       //msg $clipboard<crlf>$out;
       //// 192 set clipboard to result:
       copytext $out; 

-
////---500--- some help online, starts your default browser
"Online: RegEx Syntax Reference"
       run "http://www.regular-expressions.info/reference.html";

////---900--- open the script with notepad
"Notepad: Edit this script"
      self $ThisScriptFile, file;
      OpenWith Notepad, ,$ThisScriptFile;
////EOF