-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathCopy-Path-as-Alias.applescript
24 lines (20 loc) · 1.15 KB
/
Copy-Path-as-Alias.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
-- classes, constants, and enums used
property NSString : a reference to current application's NSString
tell application "Finder" to set thePath to POSIX path of (selection as alias)
set the clipboard to "\"" & my encodePosixtoHFS(thePath) & "\" as alias"
display notification (the clipboard) with title "Clipboard Set"
on encodePosixtoHFS(theString)
if theString contains "~" then set theString to my SearchandReplace(theString, "~", path to home folder as string)
if theString starts with "/Users" then set theString to "Macintosh HD" & theString
if theString contains "\\" then set theString to my SearchandReplace(theString, "\\", "")
if theString contains "\"" then set theString to my SearchandReplace(theString, "\"", "")
return my SearchandReplace(theString, "/", ":")
end encodePosixtoHFS
on SearchandReplace(sourceText, replaceThis, withThat)
set theString to NSString's stringWithString:sourceText
set theString to theString's stringByReplacingOccurrencesOfString:replaceThis withString:withThat
return theString as text
end SearchandReplace