I have this shell script which resolves a symbolic link (symlink) to a folder and copies it to the current working directory:
cp -R `grealpath /some/dir/symlink_to_folder` .
The command grealpath
just resolves a symbolic link when coreutils are installed on Mac OS X.
My question is: What would be the equivalent as an AppleScript? The workflow would be ideally like this: Copy one or more symbolic link-folders in Finder to the clipboard, then rightclick on another folder in Finder -> services -> run the newly created script to copy all symlinks from the clipboard to the other folder.
You could create a service like this:
cp -R "$(/usr/local/bin/grealpath "$(osascript -e 'POSIX path of «class furl» of (the clipboard as record)')")" "$1"
If the clipboard contains references to files, «class furl» of (the clipboard as record)
returns a file object for the first file.
You might also use cp -RH source target
instead of cp -R `grealpath source` target
. If the symlink and its target have different names, it uses the name of the symlink though.
-H If the -R option is specified, symbolic links on the command line
are followed. (Symbolic links encountered in the tree traversal
are not followed.)
Applescript will treat a symlink like it's just another folder, so all you have to do is duplicate the contents.
Tell application "Finder"
repeat with i from 1 to (count symlinks)
set newFolder to make new folder at destFolder with properties {name:item i of symlinks)
duplicate entire contents of item i of symlinks to newFolder
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.