Created
August 8, 2026 16:16
-
-
Save imse-ty/21feb39fcf3f5a79949bf3cd3264262b to your computer and use it in GitHub Desktop.
Copy path as link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on run | |
| set theLink to (the clipboard as text) | |
| tell application "Finder" to activate | |
| delay 0.15 | |
| tell application "System Events" | |
| keystroke "c" using {command down, option down} | |
| end tell | |
| delay 0.3 | |
| set thePath to (the clipboard as text) | |
| -- Trim trailing whitespace/newline | |
| repeat while thePath ends with return or thePath ends with linefeed or thePath ends with " " | |
| set thePath to text 1 thru -2 of thePath | |
| end repeat | |
| -- Trim leading whitespace | |
| repeat while thePath starts with " " | |
| set thePath to text 2 thru -1 of thePath | |
| end repeat | |
| -- Strip wrapping single quotes | |
| if thePath starts with "'" then | |
| set thePath to text 2 thru -1 of thePath | |
| end if | |
| if thePath ends with "'" then | |
| set thePath to text 1 thru -2 of thePath | |
| end if | |
| -- Split into path components and drop the first 5 (e.g. Volumes/angle/production/projects/doo-wop, | |
| -- or Volumes/GoogleDrive-xxxx/My Drive/folder/subfolder — whatever the mount's first 5 segments are) | |
| set AppleScript's text item delimiters to "/" | |
| set pathParts to text items of thePath | |
| set AppleScript's text item delimiters to "" | |
| -- pathParts(1) is always empty (leading slash before "Volumes") | |
| -- items 2 thru 6 = the 5 segments to drop, item 7+ = what remains | |
| if (count of pathParts) > 6 then | |
| set remainingParts to items 7 thru -1 of pathParts | |
| else | |
| set remainingParts to items 2 thru -1 of pathParts | |
| end if | |
| set AppleScript's text item delimiters to "/" | |
| set finalPath to "/" & (remainingParts as text) | |
| set AppleScript's text item delimiters to "" | |
| set combined to "[`" & finalPath & "`](" & theLink & ")" | |
| set the clipboard to combined | |
| display notification "Copied: " & finalPath with title "Copy path as link" | |
| end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment