When is an alias not an alias? In System Events

I’m migrating to OS 11 and having an issue with a few scripts. One gets the application file from a process in System Events.

It looks like an alias, but it won’t coerce to text, it won’t coerce to alias, it won’t let appleScript see if it’s in a list.

But it will coerce to a POSIX path.

Is this a sign that alias is on the way out?

→ Script Debugger 8.0.1 (8A36)
→ Mac OS 11.4 (20F71)

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Events"
   set thisApp to application process "Script Debugger"
   set applicationFile to application file of thisApp
end tell

try
   applicationFile as text
on error errMsg number errNum
   display dialog errMsg
end try
try
   applicationFile is in {}
on error errMsg number errNum
   display dialog errMsg
end try
try
   applicationFile as alias
on error errMsg number errNum
   display dialog errMsg
end try
try
   POSIX file applicationFile
on error errMsg number errNum
   display dialog errMsg
end try

But even the posix file doesn’t work in some cases.

System Events has had issues with aliases in some instances for the last few version of macOS. For example, see the following thread on MacScripters:

https://macscripter.net/viewtopic.php?id=47321

Shane suggests «class furl» as a possible workaround.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Events"
	set thisApp to application process "Script Debugger"
	set applicationFile to (application file of thisApp) as «class furl»
end tell

try
	applicationFile as text --> "Macintosh HD:Applications:Script Debugger.app:"
on error errMsg number errNum
	display dialog errMsg
end try

try
	applicationFile is in {} --> false
on error errMsg number errNum
	display dialog errMsg
end try

I’m on macOS Catalina.

Thanks, that worked!

No, it’s the result of System Events defining its own alias class. Never a great idea.

1 Like