Hello,
Very new to Applescript. Automator is more in my wheelhouse, but I’m learning.
I’m trying to write a script that will search a specific folder for another folder within it based on certain criteria. Basically I know for sure that part of the Folder Name will have specific text in it and want to target that and return the selected folder. I found a script here on Macscripter that is exactly what I am trying to achieve, but I am getting consistent errors.
set theFolder to alias "~Desktop:testing"
tell application "Finder"
items of theFolder whose name contains "~action_items"
end tell
This is the error I’m getting.
error “File alias ~Desktop:testing of «script» wasn’t found.” number -43
Ideally, I’d like to include an IF in the script so that if it is unable to find the folder within the folder, it will display a dialog and quit the application. (this will be running from an app)
would anyone like to take pity on me and try to fill in the blanks?
Taking it one step further, I’m trying to set up my If statement now… I can’t figure out what’s going wrong. without the IF, this works, but with it, it’s not returning the result of the search.
set theFolder to alias "Macintosh HD:Users:grato:Desktop:testing:"
tell application "Finder"
items of theFolder whose name contains "-action_items"
set actionItems to result
if actionItems exists then
return actionItems
else
display dialog with title "Looks like there are no action items." buttons {"Ok"}
end if
end tell
set theFolder to alias "Macintosh HD:Users:grato:Desktop:testing:"
tell application "Finder"
items of theFolder whose name contains "-action_items"
set actionItems to result -- list of items if any
if actionItems is not {} then -- empty list
return actionItems
else
display dialog with title "Looks like there are no action items." buttons {"Ok"}
end if
end tell
Note that there are three reference forms: alias, file, and Finder references. The Finder references look different like:
folder “some folder” of folder “another folder” … of startup disk of application “Finder”
Sometimes, you can’t use Finder references like this outside the “Finder” or “System Events” tell block I think. Most of the time you can though.
gl,
Model: MBP
AppleScript: 2.2.3
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)