On Jul 12, 2014, at 17:41, Nelson Byrne <email@hidden> wrote:For years I have used "returning" in my scripts. It works like the RIGHT DOUBLE ARROW of old, like so:
______________________________________________________________________
Hey Nelson,
The best way to do this sort of thing is with regular expressions.
------------------------------------------------------------------------------------------- set oldScriptText to " tell application \"Finder\" to (make new file at theOutput with properties {name:\"mylog\"}) as alias returning theLogFile
tell application \"Finder\" to get (files of theFolder where name of it ends with \".jpg\") as alias list returning theJpgList " set newScriptText to change "^[[:blank:]]*(tell application \\\"[^\\\"]+\\\" to )(.+?) returning (.+)" into " \\1set \\3 to \\2" in oldScriptText with regexp
newScriptText
-->
tell application "Finder" to set theLogFile to (make new file at theOutput with properties {name:"mylog"}) as alias
tell application "Finder" to set theJpgList to get (files of theFolder where name of it ends with ".jpg") as alias list -------------------------------------------------------------------------------------------
And if you need to do multiple find/replaces you can just stack them up.
------------------------------------------------------------------------------------------- set newScriptText to change "" into "" in oldScriptText with regexp set newScriptText to change "" into "" in newScriptText with regexp set newScriptText to change "" into "" in newScriptText with regexp ... -------------------------------------------------------------------------------------------
* Note that oldScriptText is only used in the first line. When you switch variables it's really easy to forget, use the old one, and be confused as to why your output for the new variable isn't changing as expected.
I have a reformatter script that changes a number of my old format conventions to new ones and have done this sort of thing many times over the last 20 years.
-- Best Regards, Chris
|