User Tools

Site Tools


collection:Finders_Selection

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
collection:Finders_Selection [2015/07/14 00:34]
peternlewis created
collection:Finders_Selection [2015/12/23 12:59]
ccstone
Line 1: Line 1:
-The //Finders Selection ​collection// contains the paths of each selected item in the Finder.+{{:​collection:​mac-finder-icon.png?​nolink|}} 
 +====== Working with the Finder Selection ====== 
 +**with the //[[action:​For_Each|For Each Item]]// Action using the //​[[:​Collections|Finder's Selection ​Collection]]//**
  
-In Keyboard Maestro, you work with the Finder ​Selection by using the [[action:​For_Each| For Each action ]] to iterate over the selected files. From thereyou can do whatever you would like with the files using the various file actionsor by processing with a script or other meansEven if you are writing a macro to operate on only a single itemthis is how you get that itemThere is smart action in the acton selector ​for For Each Path in the Finder Selection, which is simply ​For Each action, preset ​to iterate through ​the Finder Selection collection. You can put whatever actions you like within that action.+As you probably know, you can select multiple files and/or folders in the Mac Finder, and then perform a manual operation on the entire selection, like copymove, delete, apply tags, etc ​If ​you have an operation that you often performthen Keyboard Maestro can most likely automate that for you. 
 +===== Potential Use Cases ===== 
 +Some examples of Keyboard Maestro macros performing operations (actions) on Finder Selection:​ 
 +  - Move the selected files to another folder you often use for a specific purpose 
 +  - Assigning Mac Tags to the selection (can't be done via AppleScript) 
 +  - Renaming the selected files using a consistent prefix and number scheme 
 +  - [FIXME JM: should we add more?]
  
-Here are some examples. Set the Finder Label to Red (using ​the Plug In action for Set the Finder Label).+[FIXME ​ JM:  We need to put the detail examples in the same order as listed above Also, I suggest that we start with a simple example, like #1 above, that does NOT require something complicated like a plugin]
  
-{{ :action:label-red.png?nolink |}}+---- 
 + 
 +===== Setup of the For Each Item Action ===== 
 + 
 +In Keyboard Maestro, you work with the Finder Selection by using the [[action:​For_Each| For Each action ]] to iterate over the selected files. For each file in the selection, you can do whatever you would like with the file using the various file actions, including an [[action:​Execute_an_AppleScript|Execute Script]] Action. Even if you are writing a macro to operate on only a single item, this is how you get that item.  
 + 
 +In the For Each Item Action, you can add one or more of any of the Keyboard Maestro Actions. ​ These Action(s) will be repeated for each file in the selection. 
 + 
 +{{:collection:​km-for-each-finder.png?​nolink|}} 
 + 
 +---- 
 + 
 +===== Examples ===== 
 + 
 +**Here are some detailed examples.** \\   
 +The //​Finder’s Selection collection//​ sets the //**For Each**// Variable to the full path of each file in the selection. 
 + 
 +Note the consistency between the first three examples. And note that you could do all three in a single For Each action ​if you wanted (you would have to ensure the Move was done last of course, as that will change the path to the file). 
 + 
 +---- 
 + 
 +==== #1 - Move Selected Files ==== 
 + 
 +To move the files to the Documents folder, you would do this:\\n   
 +[FIXME ​ **JM:  There is something wrong with these images. ​ They all have a "Fix Finder Selection Bug" checkbox on them that does NOT appear on my Actions, or in Chris'​s Actions.**] 
 + 
 +{{ :​action:​move-to-documents.png?nolink |}} 
 + 
 + 
 +---- 
 + 
 +==== #2 - Assign Mac Tags to Selection ====
  
 To change the Finder Tags, you would use: To change the Finder Tags, you would use:
  
 +[FIXME ​ **JM:  There is something wrong with these images. ​ They all have a "Fix Finder Selection Bug" checkbox on them that does NOT appear on my Actions, or in Chris'​s Actions.**]
 {{ :​action:​change-tag.png?​nolink |}} {{ :​action:​change-tag.png?​nolink |}}
  
-To move the files to the Documents folder, you would do this:+----
  
-{{ :​action:​move-to-documents.png?​nolink |}}+==== #3 Rename Selected Files ====
  
-Note the consistency between themAnd note that you could do all three in single For Each action ​if you wanted (you would have to ensure ​the Move was done last of course, as that will change the path to the file).+ 
 + 
 +
 +Set the Finder Label to Red (using the Plug In action for Set the Finder Label). 
 + 
 +[FIXME ​ **JM:  There is something wrong with these images. ​ They all have "Fix Finder Selection Bug" checkbox on them that does NOT appear on my Actions, or in Chris'​s Actions.**] 
 +{{ :action:​label-red.png?​nolink |}} 
 + 
 +---- 
 + 
 +==== #4.  Pass the File Path to a Shell Script ====
  
 You can pass each file to a shell script using something like this: You can pass each file to a shell script using something like this:
Line 21: Line 71:
 {{ :​action:​pass-to-shell.png?​nolink |}} {{ :​action:​pass-to-shell.png?​nolink |}}
  
-There is a [forum topic](http://​forum.keyboardmaestro.com/​t/​working-with-the-finder-selection/​278) ​on working with the Finder selection.+---- 
 + 
 +==== #5.  Combining Multiple Actions in One For Each Item Action ==== 
 + 
 + 
 +This macro will take the selected items in the Finder and perform the following Actions: 
 +  - Get the original File Path 
 +  - Generate ​new sequenced name using the specified Base File Name 
 +    - New File Name:  `BaseFileName-n.ext` as in "`My Base File Name-1.jpg`"​ 
 +  - Add a Mac Tag to the File 
 +  - Rename the file using the text in the `baseFileName` variable and adding a hyphen and a sequential number to it. 
 + 
 +The file extension will be retained. ​ (A folder or a file with NO file extension will end up with a '​.'​ at the end of the item-name, but I'll fix that soon.) 
 + 
 +See download link for this macro below.  
 + 
 +{{ :​collection:​working-with-the-finder-selection.png?​nolink |}} 
 + 
 +---- 
 +===== Downloads ==== 
 +  - {{:​collection:​finder_rename_and_sequentially_number_selected_items.kmmacros|}} 
 + 
 +---- 
 +===== See Also ===== 
 +==== Documentation ==== 
 + 
 +  * TBD 
 + 
 +==== Forum ==== 
 +  * [Working with the Finder Selection](https://​forum.keyboardmaestro.com/​t/​working-with-the-finder-selection/​278) 
 + 
 +==== External References ==== 
 +  * TBD
collection/Finders_Selection.txt · Last modified: 2021/12/07 00:48 by peternlewis