Hey Folks,
Most Mac-users don’t know the difference between the various path-types and file-types used in scripting the macOS.
In this thread I’m going to provide some little utilities that make using AppleScript a little easier.
A common beginner AppleScripting issue is to not understand the difference between a POSIX Path and an HFS Path.
A POSIX Path uses forward-slashes to delimit directory nodes in the path:
/Applications/Calculator.app
An HFS Path uses colons to delimit directory nodes in the path:
Mercury:Applications:Calculator.app
As you can see these two path-types have different expectations of where the path should start (the root of the path).
Wikipedia: path
Wikipedia: alias
PUTTING FILE ALIASES ON THE CLIPBOARD
This first script will create a text-list of file aliases and place it on the Clipboard. Use it if/when you are asked to change a file-alias in an AppleScript to work with your system.
It is vital that a file-alias has an HFS Path like so:
set myAppAlias to alias "Mercury:Applications:Calculator.app:"
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2016/01/16 14:46
# dMod: 2017/02/05 11:43
# Appl: AppleScript
# Task: Finder-Selection to Alias(es) on Clipboard.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Finder, @Selection, @Alias, @Clipboard
------------------------------------------------------------------------------
tell application "Finder" to set finderSelectionList to selection as alias list
if finderSelectionList ≠ {} then
set AppleScript's text item delimiters to linefeed
set finderSelectionList to paragraphs of (finderSelectionList as text)
repeat with i in finderSelectionList
set contents of i to "alias \"" & (contents of i) & "\""
end repeat
set the clipboard to finderSelectionList as text
end if
------------------------------------------------------------------------------
Select the file or files you want aliases for, and run the script.
Then paste them into the script you’re working on.
-Chris
[ More to Come ]