问题
Just wondering if I can convert a "watch me do" event in Automator to applescript and then edit the resulting code? I've got a recording of entering a query (i.e. Apple1) into Google, but I'd like the query to increase ++ for each loop of the recording, so the result is Apple1, then the next loop would be Apple2, Apple3, etc. I know increments are elementary in programming, but I'm just not sure how to do it using Automator and/or applescript. Any help would be greatly appreciated.
回答1:
It may be simpler just doing it all in Applescript.
Example:
set counter to 0
set theTerm to "apple"
repeat 4 times
set counter to counter + 1
open location "http://www.google.co.uk/#hl=en&output=search&sclient=psy-ab&q=" & theTerm & counter
end repeat
Running this code will have your browser open a new search for apple1 through 4
Update: Response to Comment request:
This example shows you how to search google images and randomise the search using different terms and numbers.
set theTerms to {"apple", "orange", "banana", "pear"}
set termCount to count of theTerms
set searchLoc to "http://images.google.com/search?hl=en&site=&tbm=isch&source=hp&biw=2171&bih=1062&q="
repeat 4 times
set termRandNumber to random number from 1 to termCount
set randomSuffixNumber to random number from 1 to 7000
open location searchLoc & item termRandNumber of theTerms & randomSuffixNumber
end repeat
回答2:
A few years late but yes you can.
How to convert a list of Watch Me Do events to AppleScript:
1. Record the Watch Me Do actions
2. In the Watch Me Do window select all of the events you want to edit
3. Drag those events to a blank position below the Watch Me Do window (where you would place another Automator action)
4. Edit!
--------------------------------------------------See Below for Images--------------------------------------------------
NOTE: In Step 3, when dragging the actions to a blank space you will see a green circle icon with a white plus. Sorry I can't find the exact icon but here is one that looks close enough to give you the idea.
STEP 1
STEP 2
STEP 3
STEP 4
来源:https://stackoverflow.com/questions/15520701/automator-to-applescript-for-editing-code