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

Move selected items into ready-to-rename folder Desktop
This is a simple AppleScript for the Finder which moves the currently selected items into a newly-created folder, and puts the new folder into rename mode. I use this to quickly sort my files into properly-named folders.
(*
Move items into new folder
Author: Barry Els
Version: 1.1
*)

tell application "Finder"
  try
    
    set theSelection to selection
    
    set currentPath to ((the first item of the theSelection) as alias)
    set parentPath to currentPath
    
    if (currentPath as string) ends with ":" then -- it is a folder
      set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
      set the parentPath to (text items 1 thru -3 of (currentPath as string)) as string
      set AppleScript's text item delimiters to od
    else -- it is a file
      set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
      set the parentPath to (text items 1 thru -2 of (currentPath as string)) as string
      set AppleScript's text item delimiters to od
    end if
    
    try
      
      set newFolder to (my createFolder(parentPath))
      move theSelection to newFolder
      
      delay 0.1
      set selection to newFolder
      tell application "System Events"
        keystroke return
        quit
      end tell
      
    end try
    
  on error
    (*
    no folder or file is selected, warn the user
    *)
    
    display dialog ("Please select one or several items to group" & (theSelection as string))
    
  end try
  
end tell

on createFolder(selectedPath)
  tell application "Finder"
    set createdFolder to make new folder at selectedPath
  end tell
  
  return createdFolder
end createFolder
After saving the script, you'll want to use a keyboard shortcut tool (I use Spark) to run this script via the keyboard -- I've set the key combo for this one to Command-G.

[robg adds: This worked as described in my testing.]
    •    
  • Currently 1.63 / 5
  You rated: 1 / 5 (8 votes cast)
 
[9,989 views]  

Move selected items into ready-to-rename folder | 19 comments | Create New Account
Click here to return to the 'Move selected items into ready-to-rename folder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Move selected items into ready-to-rename folder
Authored by: mark hunte on Apr 02, '09 09:33:45AM
You can remove the discover path of items bit and if folder/file check and use:
set currentPath to container of (the first item of the theSelection) as alias
also why do you want System Events to quit after the keystroke??

---
mh

[ Reply to This | # ]

Move selected items into ready-to-rename folder
Authored by: amaloney on Apr 03, '09 07:43:25AM

Mark

I know almost nothing about writing AppleScripts

(1) With your modification what would the revised script be?

(2)No one has replied to your question about quitting System Events?
Have you altered this part of the script?
If so, what did you do?

Al Maloney



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: mark hunte on Apr 03, '09 09:29:31AM
Its a simple change. Also I would take out the quit. there is no need for it and it may cause problems.
(*
Move items into new folder
Author: Barry Els
Version: 1.1
*)

tell application "Finder"
	try
		
		set theSelection to selection
		
		set currentPath to container of (the first item of the theSelection) as alias
		set parentPath to currentPath
		try
			
			set newFolder to (my createFolder(parentPath))
			move theSelection to newFolder
			
			delay 0.1
			set selection to newFolder
			---tell application "Finder" to activate --- for testing
			tell application "System Events"
				
				keystroke return
			end tell
			
		end try
		
	on error
		(*
    no folder or file is selected, warn the user
    *)
		
		display dialog ("Please select one or several items to group" & (theSelection as string))
		
	end try
	
end tell

on createFolder(selectedPath)
	tell application "Finder"
		set createdFolder to make new folder at selectedPath
	end tell
	
	return createdFolder
end createFolder 

---
mh

[ Reply to This | # ]

Move selected items into ready-to-rename folder
Authored by: barryels on Sep 09, '09 04:14:02AM

Hi Mark,

Thanks for the feedback, i'll be incorporating it into the next release (if that's ok with you).

The "System Events / quit" bit should have been removed, i was having issues with System Events hanging when running the script from within Script Editor.

Barry



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: mannyotr on Apr 02, '09 10:13:26AM

How exactly would I use this? Sory, I am a bit of a newbie.

I have an action script I use to simply rename a group of files. Works great. This seems like it would be easier. But how would I use it?



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: homeshire on Apr 02, '09 10:48:18AM

I too would like to make use of this script, but it does not put the created folder in rename mode. I'm a bit too dense to see why it isn't working properly. anyone with a suggestion.

otherwise it does all that it says it will



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: Tim.Lance on Apr 02, '09 01:21:33PM

Same here as regards not going into rename mode.



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: amaloney on Apr 03, '09 08:21:01AM

Is it OK to add the following just before tell application "System Events"?

set newName to text returned of (display dialog "Enter New Name" default answer "" buttons {"Cancel", "OK"} default button 2)
tell application "Finder"
set name of newFolder to newName
end tell

Al Maloney



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: mark hunte on Apr 03, '09 09:54:56AM
Here is a quick change to set the name ...

(*
Move items into new folder
Author: Barry Els
Version: 1.1
*)
global newName, dialogue
set newName to "Untitled Folder"
set dialogue to "Enter New Name"
tell application "Finder"
	try
		
		set theSelection to selection
		
		set currentPath to container of (the first item of the theSelection) as alias
		set parentPath to currentPath
		try
			
			my getNameset(currentPath)
			set newFolder to (my createFolder(parentPath))
			
			move theSelection to newFolder
			
			delay 0.1
			set selection to newFolder
			--- tell application "Finder" to activate --- for testing
			tell application "System Events"
				
				keystroke return
			end tell
			
		end try
		
	on error
		(*
    no folder or file is selected, warn the user
    *)
		
		display dialog ("Please select one or several items to group" & (theSelection as string))
		
	end try
	
end tell
on getNameset(currentPath)
	
	tell application "Finder"
		set newName to text returned of (display dialog dialogue default answer newName buttons {"Cancel", "OK"} default button 1)
		if (exists (folder newName of currentPath)) then
			set dialogue to "A item with that name exists Already"
			my getNameset(currentPath)
		end if
	end tell
end getNameset

on createFolder(selectedPath)
	
	tell application "Finder"
		
		set createdFolder to make new folder at selectedPath with properties {name:newName}
	end tell
	
	return createdFolder
end createFolder

---
mh

[ Reply to This | # ]

Move selected items into ready-to-rename folder
Authored by: amaloney on Apr 03, '09 12:42:36PM

Thanks Mark
I'll use it.

Al Maloney



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: daviddingleberry on Apr 05, '09 02:18:45PM

I love this hint, very useful;

in the script line

"set newName to text returned of (display dialog dialogue default answer newName buttons {"Cancel", "OK"} default button 1)"

I changed the the default button to 2, which allows me to hit "enter" on my keyboard to create the folder, instead of requiring me click on "OK".



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: mark hunte on Apr 02, '09 03:01:32PM

If you run this from Script Editor, you will not get the result you are after.
You need to use as a app like Spark, as barryels says.

In Spark : Enable spark to run. And under the prefs, enable at start up.
Then:
1,double click on the icon that looks like a applescript app icon(on the left)
2,Paste the script into the window that drops down. Assign a hot key.
3, give it a name for the library.

Ok it, then try your new hotkey out

---
mh



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: Tim.Lance on Apr 02, '09 03:34:08PM

From Script Editor i saved it as an app and gave it a hotkey in MaxMenus. Don't see how that is different from using Spark.



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: mark hunte on Apr 03, '09 12:43:19AM

I am not sure what your point is?, No one TOLD you to use spark, use what ever you want? so long as it allows you to make your hotkeys

---
mh



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: Tim.Lance on Apr 03, '09 03:52:44AM

Wel my point is that you said not to run it from Script Editor. You said, "You need to use as a app like Spark." I said I did. Auto rename state no workie.



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: mark hunte on Apr 03, '09 04:51:04AM
Please re read my post.
"If you run this from Script Editor, you will not get the result you are after"

And I suggest you also re read you first post.
You said you where not getting the folder rename mode, This will happen if you run it in Script Editor

It is only in your last post where you first mention your attempt to use Spark.
And none of you stated HOW you ran the script before that.

It works for me in Spark with no problems.
For lack of info from you, I can only assume you ran it in script editor.
My response is to the question of how to implement it.

---
mh

[ Reply to This | # ]

Move selected items into ready-to-rename folder
Authored by: Tim.Lance on Apr 03, '09 06:36:35PM

I never said I used Spark. I never said I ran it in Script Editor. As this has deteriorated I'll now say I am done with chiming in here. I *will* keep on.



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: Anonymous on Apr 07, '09 04:56:58PM

Wow. "Works for me", eh? We're so happy for you. I'm glad you're using Spark, too. Others are not.

Carry on. As you were old chap.

I just wanted to say how this looks like a really useful little script, and maybe the logic and file operations could be done more efficiently and cross-platformilicated in a shell script; and just use Applescript for the user interface aspects. I might give it a go. I might not.



[ Reply to This | # ]
Move selected items into ready-to-rename folder
Authored by: NaOH-Lye on Apr 03, '09 12:35:11AM

Works very well. I've wanted something like this for a while, but my scripting abilities aren't up to the task. Thanks.



[ Reply to This | # ]