Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ignatius345

macrumors G3
Original poster
Aug 20, 2015
8,259
14,570
Many times a day, my workflow requires me to copy file paths to distribute to others on my team. I do that by right-clicking the file in question, holding down option and clicking "copy [file name] as Pathname". It works fine, but since the files in question are shared on Google Drive, I get a long path with a bunch of extra details specific to me and not useful for others:

'/Users/xxx/Library/CloudStorage/GoogleDrive-xxx@xxx.com/Shared drives/Projects Active/Project Name/Subfolder/Subfolder/filename.pdf'

but what I really want is just the last part: Project Name/Subfolder/Subfolder/filename.pdf

Is there a way to set up a Shortcut or other script that automatically truncate that file path when I copy it?

I would prefer not to install third-party software to do this, if at all possible.
 
Last edited:
QuickAction in Automator
quick.jpg

Code:
for f in "$@"
do
    echo "$f" | sed -e 's/.*Projects/Projects/g' | pbcopy
done
 
  • Like
Reactions: ignatius345
This reminds me of yet another idiotic change Apple made on Sequoia:

The copied path is now enclosed in single quotes ('). Single quotes work in Terminal, but they don't work in AppleScript and Objective-C, just for starters. So they now have to be manually deleted and replaced with regular quotes ("). If anything, Apple needs to enclose the path in the regular quotes, which work everywhere.

I still have to submit it as a bug to Apple. I encourage everyone to do the same.

(Yes, I know this rant doesn't help anybody.)
 
The copied path is now enclosed in single quotes (').
Only if the path has spaces. If it doesn't, no quotes are used in Sequoia 15.4.1.
In AppleScript, you could use:
AppleScript:
tell application "Finder" to set ThePath to (POSIX path of (selection as alias))
 
Only if the path has spaces. If it doesn't, no quotes are used in Sequoia 15.4.1.

I wasn't aware of this - thanks for the info. Although it doesn't make this change any better. Only makes it worse because it means even less consistency when copying paths.

Once again, the biggest problem is that Apple decided to use single quotes instead of double quotes. This is totally dumb because while double quotes would be accepted in any language, single quotes will have to be manually replaced with double quotes in specific languages.

What makes it even more ridiculous is that strings cannot be enclosed in single quotes in any of Apple's own languages: Objective-C, Swift, and AppleScript require double quotes.

In AppleScript, you could use:

Yeah, that's not what I'm talking about. I just want to copy paths in the Finder hassle-free without dealing with yet another piece of weirdness from Apple.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.