Hello,
We are experiencing some strangeness in SD8 (8.0.1) where sometimes it returns an app’s name with the .app extension and sometimes without. Previous versions of SD did not include the extension (our preferred method).
In most of our apps we run the following to get the running app’s name, version number, and path:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
on run
tell application "Finder"
set {appName, appVersion, thisAppsPath} to {(short name of (info for (path to me))), (short version of (info for (path to me))), (path to me) as alias}
end tell
end run
And here are results from two different applications:
As you can see the first two screenshots are the same app but in different locations. The third screenshot being a different app name/location.
Script Debugger is just displaying what the info for command is returning (assuming it isn’t being mangled by being placed inside a Finder tall block – you should not do that).
You’re doing some unnecessary work there any way: path to me returns an alias, and you’ll get the same result for version with a simple version.
If you’re sure you want the CFBundleName, you could use this:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set {appName, appVersion, thisAppsPath} to {((current application's NSBundle's bundleWithURL:(path to me))'s objectForInfoDictionaryKey:"CFBundleName") as text, version, path to me}
If you just want the name with the extension dropped off, you could use this:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set {appName, appVersion, thisAppsPath} to {((current application's NSURL's fileURLWithPath:(POSIX path of (path to me)))'s lastPathComponent()'s stringByDeletingPathExtension()) as text, version, path to me}
Thanks Shane. Not sure why we’ve got it within a Tell Finder block but it has always worked as expected. Removing Tell Finder works, too, as you say but still not getting the correct short name with SD8 for some reason.
We do need the running app’s name because we send the name/version through an automated version checker/updater that we created for our internal users. We’ve been using SD since version 5 or 6 and it wasn’t until SD8 that something changed. Using the app’s info has returned the correct short name but now in SD8 it is not consistent.
I’ve tried both of your suggested commands and the name/path return as expected but version just returns the string “version” instead of the app’s version number.
Even with that being worked out with this different method we have a suite of some 50+ apps using the info for method and are unlikely to go through all of them to switch methods at this time. We’ll revert back to SD7 for now.
Are you running SD8 under a different version of macOS, or on a different Mac? I just can’t see how the version of Script Debugger can make a scripting addition command behave differently – it’s something simply beyond its control.
Nope, using the same computer/OS that I have been for quite a while. Still on OS 10.15.7 (Catalina). My co-worker experienced it first and SD8 was fine for me for a while but it seemed to be all of a sudden that it’s behavior changed.
Main reason I bring it here is since we’re experiencing things differently between SD7 and SD8. Don’t know of any system updates that have been applied recently that might affect it.