Automator: Copy to clipboard the path of the selected files and folders
Tips Makradar / / December 19, 2019
Many probably know about this simple trick: if the copy in the Finder any objects and keys command+V do insert into the text box, then you get a list of the names of the previously copied files and folders. If the names you want to add the path to the respective objects, just open Automator and concoct it simple service.
That's how the service should look like as a finished product:
The second action - Show Growl Notification - add optional, but I prefer to be clearly understood when "Avtomator" finished its work, and Growl notification for me, the most convenient option.
As to the first act, it is the whole point of it. AppleScript script takes as input an array of data files and folders that should be allocated to access the service. Pay attention to the content of the header of the algorithm: the service is connected only to the Finder and the team call the service will appear in the context menu only for folders and / or files.
Full AppleScript script code is as follows:
on run tell application "Finder" copy selection to theSelected set outputPathList to {} repeat with anItem in theSelected copy (POSIX path of (anItem as alias)) to end of outputPathList end repeat set AppleScript's text item delimiters to return set outputString to outputPathList as string set AppleScript's text item delimiters to "" set the clipboard to outputString set input to outputString end tell return input. end run
The first half of the code performs all the steps required to transfer the path to objects from the format "Disk: Folder1: Folder2:...: papkaN: imya.rasshirenie" in the format "/Papka1/papka2/.../papkaN/imya.rasshirenie" (Second format - called POSIX-format recording "coordinates" of the file system object). The second part of the code creates a text list - every path to the object will be located on a separate line.
Of course, the two operator in the 15 and 18 lines, and can be removed. However, I left them in the case of the current actions Run AppleScript (Run AppleScript) the resulting array of strings will need to transfer for further processing some other action.
By inserting this code and adding optional challenge Growl messages, save the service of convenience to himself by the name (for example, Copy the path of objects). Immediately after that, you can go to the Finder and select multiple files and folders, click on the right mouse button - from the context menu, under command call services, you will see a fresh point. By clicking on it, you will copy the path to the selected objects. Will only go to any text program and keys command+V ready to insert an array of strings.