Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.6: Gather Finder Items with a new Service System 10.6
Snow Leopard only hintI am trying to wean myself from numerous utilities that add System and Finder functionality and replace them with Services wherever possible. One indispensable (for me) feature of Unsanity's FruitMenu is the 'Gather Items in New Folder' Contextual Menu Item.

I tried to replace this with vanilla AppleScript and Automator, but AppleScript doesn't like letting you play around in certain directories, especially the Trash (.Trash) folders.

Other hints here approach this task with varied techniques; i found none that played well in trash or named folders automatically and uniquely to my tastes.

One example of why I need to these unique abilities is, after updating iOS apps, they all land in the Trash, and, in case I wish to revert to these older versions (c.e.: Twitter v3.3), I make a practice of opening the trash, gathering all .IPA files into a new folder, and moving that folder to a safety archive for easy retrieval.

This service is also exceptionally useful for cleaning up the Downloads folder, Pictures, Desktop, etc.; anytime you have a selection of Finder objects (files and folders) you wish to gather into a new folder.

The script below can be run as a plain AppleScript from something like FastScripts or AppleScript Menu, but is best run as a Service item.

To make the Service:
  • Open Automator; make new file of type 'Services.'
  • Set 'Service receives selected' to 'files or folders' in 'Finder.'
  • Select Utilities » Run AppleScript (double-click to insert in workflow).
  • Replace "(* Your script goes here *)" with the AppleScript below; be sure to not overwrite the 'on run', 'return input' and 'end run' parameters.
  • Save your new Service as 'Gather Items in New Folder' or similar name.
To use this Service:
  • Select multiple items (they need not be contiguous or even in the same folder).
  • Right-click (Control+Click) to access the above-named Service; and wait for completion.
  • Press 'Return' to immediately Rename the newly created folder as desired.
Please Note: I am a bit rusty at AppleScript; I had to fool around with shell to coerce and workaround Error -1700 permissions issues; please feel free to comment and offer cleaner solutions.
tell application "Finder"
  (* what files do you want to gather into a new folder? *)
  set selectedItems to selection
  if selectedItems is not {} then
    (* topLevelName assures the uppermost file-level-directory will be selected in case of multiple selections in list or column view. *)
    set topLevelName to name of item 1 of selectedItems
    (* silly set of workarounds to override vanilla AppleScript's lack of permission when playing in the .Trash folders *)
    set selectionPath to POSIX path of file ((item 1 of selectedItems) as string)
    set selectionPath to ((characters 1 thru ((offset of topLevelName in selectionPath) - 1)) in selectionPath) as string
    (* Modify path string to create a unique target folder using date and time *)
    set dateString to do shell script "date \"+%Y.%m.%d %a %I.%M.%S %p\"" -- this line broken out for easy editing
    set newFolder to selectionPath & (dateString & " Gathered Items") -- rearrange as you please; is set this way for proper name sorting
    (* more workarounds to allow playing in the .Trash *)
    do shell script "mkdir " & quoted form of newFolder
    set newFolder to (POSIX file newFolder) as alias
    move selectedItems to newFolder
    reveal newFolder
  end if
end tell

[crarko adds: I tested this, and it works as described. I've mirrored a copy of the final working Service here. Just open the workflow in Automator and re-save it as a Service.]
    •    
  • Currently 3.40 / 5
  You rated: 5 / 5 (5 votes cast)
 
[8,011 views]  

10.6: Gather Finder Items with a new Service | 18 comments | Create New Account
Click here to return to the '10.6: Gather Finder Items with a new Service' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Gather Finder Items with a new Service
Authored by: jazzbri on Mar 10, '11 08:45:08AM
Another method, using this script:

try
	tell application "Finder" to set the this_folder to (folder of the front window) as alias
on error -- no open windows
	set the this_folder to path to desktop folder as alias
	
end try

tell application "Finder"
	set selected_items to selection
	
	set thefoldername to text returned of (display dialog "Folder name:" default answer "new folder")
	
	
	set theFolder to (make new folder at this_folder with properties {name:thefoldername}) --added "set theFolder to.."
	
	repeat with x in selected_items
		move x to theFolder
	end repeat
	
end tell
I run this script from Butler (tied to a Shift-Option-N keyboard shortcut). It's worked perfectly for me for years :)

[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: Frederico on Mar 10, '11 09:21:36AM

I wonder if Craig shouldn't change the Hint title to reflect this script/Service's unique ability to play in forbidden folders?

I was using similar scripting myself, but, as I stated, this did not allow me to create folders directly inside the Trash (.trash) folder.

You work around the aforementioned -1700 permissions errors by tossing the newly created target folder onto the Desktop, which is fine, I guess, for you, but for my workflow it adds yet another manual step to close the Trash, go locate the new folder on the Desktop, and then move it where I want it -- which may very well be in the very location I am already working, including the Trash.

A similar burden is placed on me if I am in the /System or /Library or /Applications folders, which, admittedly, is not something most users will do, but many advanced users will be in the several-levels-deep, normally-off-limits System folder, reorganizing various components for troubleshooting needs.

My script/Service (also invoked by Keystroke) gives me an automatic, guaranteed unique, sortable folder name, leaves the target where I am working, and preselects it on the assumption I wish to take further action on it -- which for me regularly includes yet another Service (also by Keystroke) to move the folder to a specified location, obviating the need to drag it manually.

Looking at your script, I could remove the dialog and add my code to auto-name it; and I could also add code to predict the need to move the new folder back into the Trash as needed, and it would indeed have met the Vanilla AppleScript goals. Interesting food for thought.

PS: I note that you use a Repeat function to move your items; this is slow (with a large list) and unnecessary; a single batch move as I have done in my script will move them all in one shot.

Thanks for the feedback.


F



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: jazzbri on Mar 10, '11 09:28:04AM

You're right about the repeat being slooooow when contending with a bunch of files. I still like my keyboard shortcut... I'll work your service into it and have the best of both worlds :)



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: NaOH-Lye on Mar 10, '11 10:24:18AM
There's also the script in this hint, Move Selected Items Into Ready-To-Rename Folder. I use it with a script launcher, but I presume it could be run as a service.

[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: Frederico on Mar 10, '11 10:36:59AM

Yes, I saw that script before rolling my own; again, none of the scripts posted here or anywhere else I easily found could work with Folders *directly* in the Trash or other System-owned folders, and will throw -1700 permissions errors.

I can't believe I'm the only one who needs to work in such restricted directories, hence my posting this alternative.

I've been using the Unsanity Fruit Menu haxie since it was in original beta form, since the literal birth of OS X, and I'd come to rely on it for many features; but changes in my actual work have negated it only to its Contextual menu features, and a couple other minor toys that I am able to recreate either with Services or *native* cocoa apps that don't cause other conflicts.

I will still miss APE and MenuMaster; this last simple tool allowed me to fix an issue with Adobe GoLive that is not fixable in any other way, and will force me to finally spend money on a new web development app and relearn a set of skills and workflows I have no interest in doing, but must still maintain a few websites. PITA. In the meantime I only activate APE and MenuMaster when I need to work in GoLive; which is just a drag for having to logout/login/logout to cycle the features.



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: NaOH-Lye on Mar 10, '11 10:56:18AM

Sorry about that. I regularly use the script I linked, and I was certain I've used it with files in the Trash. I should have tested first.



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: NaOH-Lye on Mar 10, '11 10:59:48AM

So what is it that MenuMaster allows you to to GoLive?



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: Frederico on Mar 14, '11 11:38:27PM

AGL (nee CyberStudio) has several hidden, undocumented keyboard shortcuts that, because they do not exist in Menubar menus, are not modifiable by OS X Keyboard Shortcuts; nor are they included in the built-in Keystroke Editor from Adobe; worse, a few of these hidden keystrokes were stepped on by OS X System global keystrokes (that Adobe failed to note had been deprecated and warned of two years prior).

MenuMaster is the only fast, easy, reliable method to "inject" shortcut overrides at a System level; most notably, MM allows you to actually REMOVE keystrokes altogether; e.g., the OS X global Preferences keystroke is Command-[comma]; MM actually lets you *delete* this keystroke altogether, thus allowing the Command-[comma] keystroke to be passed through to AGL core code.

Alas, while MM is out in beta form for Snow Leopard, it's pretty unreliable for production/full-time use; and it took Unsanity something like 18 months to get it that far, and it has not been updated in nearly 6 months since; so I have zero confidence it will, one, become stable ever, and two, be updated for Lion. Though that point is moot, apparently; as even if Unsanity comes through, Apple seemingly has deprecated Rosetta, and all carbon & PowerPC apps will die, anyway.

As I said, I do not develop for Web anymore, but maintain dozens of (low-tech, but fully functional) sites created in AGL, and, as the maintenance pays little, I have no real desire to not only buy new software, but learn said software, either.

I am *PRAYING* for a VM solution with Lion that allows me to run not only SL, but, even better, 10.5 Leopard in VM; which was the last version that AGL *and* MM lived together reliably. Heck, I probably will even drop back to Tiger, if not Panther, given that all I intend to run in a VM would be AGL 6 and Photoshop (6 or 7), Illustrator (10) or CS3 (suite) for short amounts of time.



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: JMoVS on Mar 11, '11 01:57:02PM

Hey, did you think about folder actions like this example script woking absolutely fine for me in Trash?
http://hints.macworld.com/article.php?story=20100121075428946
Just modify it for your needs!



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: Frederico on Mar 14, '11 11:43:00PM

Folder Actions are somewhat intriguing, thanks for the suggestion.

I already make extensive use of FA in many other tasks; I had not considered it for the Trash and yanking .IPA files. The thing is, I tend to be selective on which IPAs I actually save; many times I really don't care to archive every single version of every single app. By reviewing it manually each time, I only select and archive those which matter.

It would take only a bit of adjustment, I think, to know that *ALL* IPAs are being archived, and force myself to review the actual archives once a week or so to cull the chaff and prevent wasted disk and Time Machine space.

I'll report back if I get a functional FA working with the Trash.



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: Danni on Mar 10, '11 01:03:58PM

You can also use OnMyCommand, from abracode, to do this (as well as many other useful things). And it does work inside the trash or other protected folders.



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: Frederico on Mar 14, '11 11:51:48PM

As stated in the post, I am trying to relieve the need for as many third party utilities as I can and move as many actions to native/inclusive OS X tools as possible, to better prep for the leap to Lion, which, presumably to be sans Rosetta, will be an even more painful transition that was Leopard and Snow Leopard.

Perhaps your suggestion will be of use to those who don't like to create their own solutions and don't mind paying an additional cost in dollars and CPU and compatibility overhead, however.

Cheers (

F



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: kquinn on Mar 11, '11 03:05:24AM

I use this simple Applescript (and it works for files in the Trash):

tell application "Finder"
set theSelection to selection
choose folder
set theDestination to the result
move theSelection to theDestination
end tell

Save it as an app, and trigger it with a Butler shortcut.



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: Frederico on Mar 14, '11 11:47:35PM

True, your script works from "the outside" of the Trash, but it cannot even Choose, let alone *create* a folder within the Trash itself; nor does it automate folder naming, etc.

To me, the whole point of scripting repetitive tasks is to *eliminate* as many human actions as possible. To use your script in place of mine, I would add not less than 30 additional keystrokes and mouse clicks to an action I perform 2-3 times weekly.

Thanks, anyway (:



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: ovek on Apr 28, '11 01:11:38PM

First, I need to excuse myself, as I am new to this site (and to be honest: the Mac platform). I'm an old Windows-user trying to translate my ancient .bat-file knowledge to the modern world...

I've been researching these scripts myself, but my needs seem simpler than these scripts are written.

See, after I've downloaded new versions of iOS apps, I always move ALL the .ipa-files from the trash to the same folder ("/Volumes/1TB/backup/old iOS apps (saved from trash)/".

To quote yourself Frederico: "To me, the whole point of scripting repetitive tasks is to *eliminate* as many human actions as possible.". I agree totally. In fact, I would prefer to have my needs taken care of totally automatically, in other words: the second an .ipa-file enters the trash, it's automatically moved to my predetermined folder.

I assume folder actions are needed here? I suspect this script might even be quite short, as the actions needed are fairly simple. I would appreciate some help with how to write this from you gurus!



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: asmeurer on Jun 08, '11 06:20:52PM

It looks like Lion will have this feature built-in.



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: Frederico on Jul 22, '11 01:38:15PM

This feature is indeed built in but *STILL* does not work in the Trash.

Also, see post below: WARNING: Do NOT use this script as is in Lion!! Devastating results to the Desktop folder and its special privileges!! Will be reworking the script and posting results later!



[ Reply to This | # ]
10.6: Gather Finder Items with a new Service
Authored by: Frederico on Jul 22, '11 01:39:24PM
WARNING: Do NOT use this script as is in Lion!!

Devastating results to the Desktop folder and its special privileges!! Will be reworking the script and posting results later!

Edited on Jul 22, '11 01:41:39PM by Frederico


[ Reply to This | # ]