Why a handler is not called within the tell block?
Error is -1708
on stub() -- method is not called in tell block
end stub
tell application "Finder"
stub()
end tell
Within a tell SOMETHING block, AppleScript looks up commands within SOMETHING. In this case, it's looking for a stub command within application "Finder"; this obviously doesn't exist. To tell AppleScript to look up the function you've defined, you write my stub(); the my forces it to look in the body of the current script rather than in application "Finder". In this case, this gives you:
on stub()
-- ...
end stub
-- ...
stub() -- Works fine
-- ...
tell application "Finder"
-- ...
my stub() -- With the `my`, works fine
-- ...
end tell
Related
I'm trying to use parameter specifications for the application process class from System Events:
on someHandler(anInt as integer, anAppProcess as application process)
end someHandler
anInt works fine, but trying to add anAppProcess results in a Syntax Error ‘Expected “,” or “)” but found identifier.’ on the word process. I believe this is because application process is not in scope and is instead parsed as application as a single class and the token process, instead of the class application process.
I've also tried:
tell application "System Events"
on someHandler(anAppProcess as application process)
--^^ Expected “end” or “end tell” but found “on”.
end someHandler
end tell
on someHandler(anAppProcess as application "System Events"'s application process)
-- ^ Expected “,” or “)” but found “"”.
end someHandler
tell application "System Events" to set ap to application process
on someHandler(anAppProcess as ap)
-- ^^ Expected class name but found identifier.
end someHandler
Is there a way to get application process in scope or otherwise use parameter specifications for classes from other applications?
This also shouldn't be related to application process containing a space; I have tried this for single-word classes from other applications as well.
A handler must be declared on the top level of the script.
But you can use an using terms from block which is not treated as a level
using terms from application "System Events"
on someHandler(anAppProcess as application process)
end someHandler
end using terms from
But I have no idea what you are going to coerce to application process
I have created a rule that messages move into a subfolder when they according to certain criteria.
Additionally, I have saved in this rule an AppleScript that this mail copied subsequently into an DMS.
It is working.
My problem is, that the name of the subfolder is (for now) not passed to the script. It contains only "INBOX":
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with theMessage in theMessages
set nameAccount to name of mailbox of theMessage # here is the problem !
try
tell theMessage
— at this point get the data out of the mail
end tell
tell application id „DMS“
— here the data will save to the dms
end tell
end try
end repeat
end tell
# end try
# end tell
end perform mail action with messages
end using terms from
How do I get the name of the destination folder from the active mail rule?
Instead of the name get the whole mailbox object, it contains the actual reference in the folder hierarchy, to create a subfolder you need the reference anyway.
set theMailbox to mailbox of theMessage
PS: the tell application "Mail" block is not needed, the using terms block is sufficient to evaluate the terminology.
Can anyone explain why the following piece of Applescript code returns an error:
tell application "Photos"
set idList to {"v3xzjwPQT0y8a844gLHLHWg", "v3w3twPQT0y%%844gLgf4Wg"}
set itemList to every media item in application "Photos" where its id is in idList
log (count of itemList)
end tell
The error is:
error "Photos got an error: Can’t make {\"v3xzjwPQT0y8a844gLHLHWg\", \"v3w3twPQT0y%%844gLgf4Wg\"} into type specifier." number -1700 from {"v3xzjwPQT0y8a844gLHLHWg", "v3w3twPQT0y%%844gLgf4Wg"} to specifier
There is no error in this line of code using OSX 10.9 and iPhoto. Perhaps something changed in "Photos"/10.10?
In any event, do you still get the error if you move the line of code
set idList to {"v3xzjwPQT0y8a844gLHLHWg", "v3w3twPQT0y%%844gLgf4Wg"}
to just before the Tell "Photos" block? The error is saying "Photos" got the error trying to make the idList. So try defining the idList without Photos. I would think the list could be defined without telling Photos to do it.
I have the same issue. My goal is to get all images that are not in a certain album.
The error rises in the line
set itemList to every media item in application "Photos" where its id is in idList
Also this one-liner results in an error
set itemList to every media item in application "Photos" where its name is in {"bla"}
What works is the following line
set itemList to every media item in application "Photos" where its name is "bla"
But that does not solve the problem. Maybe someone has a suggestion how to do it.
That feature does seem to be broken in Photos 4. You can work around it in a couple of ways. If your list is simple and fixed you can build up a command using or statements like so:
set itemList to every media item whose id is "wi9HoFU0SKCDianaQBtJBg" or id is "DT29HF1lRgCKOaIZFHoHrQ"
If you need something more flexible, you can use a repeat loop and build up the list through individual searches:
set idList to {"wi9HoFU0SKCDianaQBtJBg", "DT29HF1lRgCKOaIZFHoHrQ"}
tell application "Photos"
set newList to {}
repeat with thisID in idList
set anItem to (first media item whose id is thisID)
copy anItem to end of newList
end repeat
end tell
I have an AppleScript-ObjC app, which is sandboxed, and am running into an issue with trying to get or set properties of an iTunes track. Oddly, I can successfully run the get/set methods when working with an iTunesTrack object, but cannot when working with an iTunesFileTrack object.
Example:
set iTunesAppObject to current application's SBApplication's applicationWithBundleIdentifier_("com.apple.iTunes")
set trackToEdit to iTunesAppObject's currentTrack()
set trackPersistentID to trackToEdit's persistentID()
trackToEdit's setName_("TEST NAME") -- this works, trackToEdit is an iTunesTrack object
-- GET ALL SOURCES FROM ITUNES
set iTunesSources to iTunesAppObject's sources()
-- REPEAT FOR EVERY SOURCE
repeat with aSource in iTunesSources
-- LOOK FOR MAIN LIBRARY SOURCE
if (aSource's |kind|()) is 1.800169826E+9 then
set mainLibrary to aSource
exit repeat
end if
end repeat
set libraryPlaylist to mainLibrary's |libraryPlaylists|() -- GET LIBRARY PLAYLIST
set libraryPlaylist to libraryPlaylist's objectAtIndex_(0)
set allTracksInPlaylist to libraryPlaylist's |fileTracks|() -- GET ALL TRACKS IN PLAYLIST
-- SET UP PREDICATE TO FIND TRACK WITH ID
set searchPredicate to current application's NSPredicate's predicateWithFormat_(("persistentID == " & quoted form of (trackPersistentID as text)))
allTracksInPlaylist's filterUsingPredicate_(searchPredicate) -- FILTER ARRAY
set trackToEdit to allTracksInPlaylist's objectAtIndex_(0) -- GET REMAINING ITEM IN ARRAY, RETURNS iTunesFileTrack OBJECT
log trackToEdit -- returns a seemingly valid iTunesFileTrack object
trackToEdit's setName_("TEST NAME") -- does NOT work, result in sandbox dispatch deny error in Console.app
log trackToEdit's |name|() -- does NOT work, returns null/missing value
Everything works when the app is not sandboxed. I have added pretty much every entitlement to my project, including:
com.apple.iTunes.library.read-write
com.apple.iTunes.user-interface
com.apple.iTunes.playerInfo
com.apple.iTunes.playback
Can anyone think of a way to get around this? Is is possible to "convert" an iTunesFileTrack object to an iTunesTrack object? Thanks in advance for any suggestions!
bless your heart. try this out:
property aTrack : missing value
on getTrack_(sender)
tell application "iTunes"
set aTrack to (get current track)
end tell
end getTrack_
on renameTrack_(sender)
set name of aTrack to "whatever"
end renameTrack_
I am thoroughly stumped by this problem. I have some standard functions that I saved in a compiled AppleScript file, let's call it functions.scpt. In another script, I use load script to load a script object to functions.scpt:
set funcs to load script "path/to/functions.scpt
I have one handler in functions.scpt called icon(). For whatever reason, if I try to call this function more than once in my other script, I get an error. Here's some quick example code:
--called once
funcs's icon()
--called twice
funcs' icon()
Whenever I do this, I get the following error: error "«script» doesn’t understand the “icon” message." number -1708 from «script» to «class icon».
Why can't I call the same function from a loaded script object twice? How can I fix this? I need to call it multiple times.
Thank you to #CRGreen and #jweaks. I actually just found the answer on this thread: https://stackoverflow.com/a/13256042/2884386
I had set a variable icon within the handler, which was overwriting the handler. So when the other script tried to access it the second time, it wasn't pointing to the handler, but to the variable. I rewrote the internal variables, and that fixed it.
So, this is (as an example) correct:
on icon()
set _icon to "path/to/icon.png"
return POSIX file _icon
end icon
Whereas this is incorrect:
on icon()
set icon to "path/to/icon.png
return POSIX file icon
end icon