I know, the default application for Finder aliases files is Finder itself. So, doesn’t understand why following returns Terminal.app. Is the Terminal.app somewhat involved indeed or this is info for command bag?
set myDoc to choose file of type "com.apple.alias-file"
set defaultApp to default application of (info for myDoc)
.
So far, I’ve used this solution to the problem:
my deafultApplication(choose file with invisibles)
on deafultApplication(theAlias)
tell application "System Events" to set typeIdentifier to type identifier of file (theAlias as text)
if typeIdentifier is "com.apple.alias-file" then return path to application id "com.apple.finder"
try
return default application of (info for theAlias)
on error
return "No default application installed"
end try
end deafultApplication
The info for command is deprecated, which could have something to do with it. Telling System Events to get the properties for an object is the recommended alternative.
I rewrote the script telling to System Events instead of deprecated info for. It works, but still can’t be simplified because System Events returns for Finder alias files the Terminal.app as default application, like the deprecated info for.
my deafultApplication(choose file with invisibles)
on deafultApplication(theAlias)
set theHFS to theAlias as text
tell application "System Events"
set typeIdentifier to type identifier of disk item theHFS
if typeIdentifier is "com.apple.alias-file" then return path to application id "com.apple.finder"
try
return (default application of disk item theHFS) as alias
on error
return "No default application installed"
end try
end tell
end deafultApplication
I am absolutely sure that the default application for Finder alias files is the Finder itself. The fact that all methods return the Terminal only tells me that the Finder alias class itself has its flaws, and the methods have nothing to do with it.
In addition to this strangeness, I noticed that the choose file dialog does not allow you to select the Finder alias file (itself) that points to the folder. In general, this is a very, very strange class, so in order to work with it completely correctly, I will have to use valid HFS paths or AppleScript aliases instead of choose file.
So, the correct handler in the completed form for me is this:
my deafultApplication("Apple HD:Users:123:Desktop:Movies alias") -- Finder alias to my Movies folder
on deafultApplication(HFS) -- valid HFS path required
tell application "System Events"
set typeIdentifier to type identifier of disk item HFS
if typeIdentifier is "com.apple.alias-file" then return path to application id "com.apple.finder"
try
return (default application of disk item HFS) as alias
on error
return "No default application installed"
end try
end tell
end deafultApplication
The appleScript alias class has very little to do with the Finder alias file.
Here’s the relevant info returned by info for; system events and finder:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set theFiles to {alias "Macintosh HD:Users:edstockly:Desktop:Liz.jpg alias", alias "Macintosh HD:Users:edstockly:Desktop:Liz.jpg"}
repeat with thisItem in theFiles
set fileClass to class of thisItem
info for thisItem
--name:"Liz.jpg alias",
--alias:true,
--name extension:missing value
--default application:alias "Macintosh HD:System:Applications:Utilities:Terminal.app:"
--kind:"Alias"
--file type:"alis"
--file creator:"MACS"
--type identifier:"com.apple.alias-file"
tell application "Finder"
properties of thisItem
--alias:true
--name extension:missing value
--displayed name:"Liz.jpg alias"
--default application:alias "Macintosh HD:System:Applications:Utilities:Terminal.app:"
--kind:"Alias", file type:"alis", file creator:"MACS"
--type identifier:"com.apple.alias-file"
end tell
tell application "System Events"
properties of thisItem
--file type:"alis"
--kind:"Alias"
--creator type:"MACS",
--type identifier:"com.apple.alias-file"
--default application:alias "Macintosh HD:System:Applications:Utilities:Terminal.app:",
end tell
end repeat
The default appication is terminal.
I didn’t say somewhere that these two classes are related somehow.
Maybe the default application for alias files should be finder, but the default application for alias files is Terminal.
As I understand it, Finder.app stupidly writes Terminal.app as the default application instead of itself when it creates Finder alias file, in the metadata.
But this cannot be, because Terminal.app has no idea about file references (although this class is listed in its dictionary, erroneously). Simple test:
set FinderAliasHFS to (choose file of type "com.apple.alias-file") as text
tell application "Terminal" to open file FinderAliasHFS
.
.
Making files list (described in the dictionary for open command) doesn’t help as well:
set FinderAliasHFS to (choose file of type "com.apple.alias-file") as text
tell application "Terminal" to open {file FinderAliasHFS}
.
.
The only kind of reference that Terminal.app opens is AppleScript Alias. But its use in Terminal.app only makes sense with its exported settings files (.terminal extension). So, this works:
set applescript_Alias to (choose file of type "terminal")
tell application "Terminal" to open applescript_Alias
When run under Sierra, the resulting default app for an alias-file is Finder.
[format]alias “MacHD:System:Library:CoreServices:Finder.app:”[/format]