Couldn’t find any information on this googling it or searching this forum…
I can’t get the Enhanced Applet to run from the Dock, but it runs fine using the “Invoke Open Handler” feature within Script Debugger. If I create a new Enhanced Applet, and insert display dialog (theFile as text)
into the processAFile handler, using the “Invoke Open Handler”, it alerts the file paths.
When I save it, slide it into the dock, and drop the same files onto it, I get the error System Events got an error: Can't make name of file "Macintosh HD:Users:me:Desktop:Image.jpg" into type specifier.
I’m on MacOS Mojave. I suspect it’s a permission issue relating to System Events, but I could be wrong. Has anyone else had this issue or know how to resolve it?
Thanks!
Can you post complete code that can be tested?
Sure thing.
The applet is sitting in my Applications folder.
Script Debugger 7 v7.0.12 (7A112)
iMac (MacOS Mohave 10.4.6)
It’s the default code starting a new Enhanced Applet, with display dialog (theFile as text)
inserted into the processAFile(theFile)
handler.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
on prepareToProcessFiles(theFiles)
set progress description to "YOUR SCRIPT'S DESCRIPTION"
-- your initialization code goes here
return theFiles
end prepareToProcessFiles
on processAFile(theFile)
-- your code to process theFile goes here
display dialog (theFile as text)
end processAFile
on cleanup()
-- your cleanup code goes here
end cleanup
on open theFiles
try
-- Initialization...
set progress total steps to -1
set progress completed steps to 0
set progress description to ""
set progress additional description to "Preparing to process files..."
set theFiles to prepareToProcessFiles(theFiles)
-- Process Files...
set progress total steps to count of theFiles
set progress completed steps to 0
repeat with aFile in theFiles
tell application "System Events" to set theFileName to name of aFile
set progress additional description to "Processing “" & theFileName & "”..."
processAFile(contents of aFile)
set progress completed steps to progress completed steps + 1
end repeat
-- CLeanup...
set progress total steps to -1
set progress completed steps to 0
set progress additional description to "Cleaning up..."
cleanup()
on error errMsg number errNum from errFrom to errTo partial result errPartialResult
-- Cleanup...
set progress total steps to 0
set progress completed steps to 0
set progress additional description to "Cleaning up..."
cleanup()
error errMsg number errNum from errFrom to errTo partial result errPartialResult -- resignal the error
end try
end open
Invoking the Open Handler from the application works.
Dropping a file gives
System Events got an error: Can't make name of file "Macintosh HD:Users:me:Desktop:Image.jpg" into type specifier.
The issue is that System Events can’t deal with modern file references («class furl»
). You could do something like:
tell application "System Events" to set theFileName to name of (aFile as alias)
but really, you’d be better off parsing the name from aFile as text
yourself.
1 Like
Thank you! That allowed the default script for the Enhanced Applet work.
The script breaks on a line that is part of the boilerplate for an Enhanced Applet. Boilerplate never makes it to processAFile(theFile) without System Events throwing a fit.
Would it be a good idea to fix that for the next release? Bit tricky to debug that for a newcomer.
1 Like