• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: returning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: returning


  • Subject: Re: returning
  • From: Christopher Stone <email@hidden>
  • Date: Sun, 13 Jul 2014 14:07:23 -0500

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.

Using the Satimage.osax or Shane Stanley's regex find/replace library for Mavericks make the task of making serial edits in script-text quite easy.

-------------------------------------------------------------------------------------------
# REQUIRES the Satimage.osax be installed!
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

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >returning (From: Nelson Byrne <email@hidden>)

  • Prev by Date: Re: Article on making an app scriptable
  • Next by Date: Doing time
  • Previous by thread: returning
  • Next by thread: RE: returning
  • Index(es):
    • Date
    • Thread