AppleScript alias is a special kind of file specifier which keeps the reference even if the file is moved or renamed. AppleScript alias holds always the reference to the original file.
Finder alias is a very small file containing a pointer to a original file like an UNIX symlink. The AppleScript equivalent is alias file
Pretty much anything. It can be an AppleScript file or alias, an HFS path, a POSIX path, or an NSURL. The idea is that you pass whatever you have, and let the library convert it. So the first thing most handlers in the lib do is pass it to this handler to get an NSURL:
on makeURLFromFileOrPath:theFileOrPathInput
-- make it into a Cocoa object for easier comparison
set theFileOrPath to item 1 of (current application's NSArray's arrayWithObject:theFileOrPathInput)
if (theFileOrPath's isKindOfClass:(current application's NSString)) as boolean then
if (theFileOrPath's hasPrefix:"/") as boolean then -- full POSIX path
return current application's class "NSURL"'s fileURLWithPath:theFileOrPath
else if (theFileOrPath's hasPrefix:"~") as boolean then -- POSIX path needing ~ expansion
return current application's class "NSURL"'s fileURLWithPath:(theFileOrPath's |stringByExpandingTildeInPath|())
else -- must be HFS path
return current application's class "NSURL"'s fileURLWithPath:(POSIX path of theFileOrPathInput)
end if
else if (theFileOrPath's isKindOfClass:(current application's class "NSURL")) as boolean then -- happens with files and aliases in 10.11
return theFileOrPath
else -- must be a file or alias
return current application's class "NSURL"'s fileURLWithPath:(POSIX path of theFileOrPathInput)
end if
end makeURLFromFileOrPath:
I installed the Shane’s library and do not understand what variables I need to substitute of aFileOrPath and originalFileOrPath to get the alias, because i have only 1 “ path to file from an array.
There are handlers for creating alias files, symbolic links and hard links, as well as for retrieving the path of an item an alias file points to and resolving any symbolic links in a path:
FMLib's createAlias:aFileOrPath pointingTo:originalFileOrPath
set originalItemPath to FMLib's originalFromAlias:aFileOrPath
FMLib's createSymlink:aFileOrPath pointingTo:originalFileOrPath
set originalItemPath to FMLib's resolveSymlinksIn:aFileOrPath
FMLib's createHardLink:aFileOrPath linkedTo:originalFileOrPath
i have got an array “ vectorFilePosixPaths, and i want to get an alias of all paths.
Wath i need to do?
I have only one variable (aFile), and then need another.
repeat with aFile in vectorFilePosixPaths
--> aFileOrPath
--> originalFileOrPath
FMLib's createAlias:aFileOrPath pointingTo:originalFileOrPath
end repeat
You need to decide what name and path you want for the alias. Let’s say you want them on your desktop, with the same name as the originals which are not on your desktop. You could do something like this:
use FMLib : script "FileManagerLib"
use scripting additions
on open vectorFilePosixPaths
set desktopPath to path to desktop as text
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
repeat with aFile in vectorFilePosixPaths
set theName to text item -1 of (aFile as text)
(FMLib's createAlias:(desktopPath & theName) pointingTo:aFile)
end repeat
set AppleScript's text item delimiters to saveTID
end open