Prompt to Rename Files

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Re: Prompt to Rename Files Thu May 24, 2012 12:33 pm • by Shawn Wright
Perfect, works like a charm. I had to rename the token, for some reason applescript didn't like NewFileName, it wanted NewFilename.

Thanks for the help, you really helped me out.

Shawn
Shawn Wright
 
Posts: 5
Joined: Wed May 23, 2012 3:11 pm

Re: Prompt to Rename Files Thu May 24, 2012 12:38 pm • by a_freyer
No problem at all! Hazel is far beyond an essential tool for me and I try my best to show others how powerful it really can be.

For reference, the AppleScript probably kept changing the token back to NewFilename because that's what the variable was defined as earlier in the script. It was trying to outthink you. :-)

Also, and this may go without saying, any of the text in quotations in the script can be changed to your needs - so "Rename Screenshot" could be "Rename SnapScan" etc.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Prompt to Rename Files Wed Sep 05, 2012 6:00 pm • by EnriqueO
Hi,
I guess new version 3 breaks this script, I've uptdated it just by getting rid of the icon (which was changed for the new MacBook retina display) here's the script:

Code: Select all
tell application "Finder" to set shortName to name of (theFile as alias)

set theDialogText to "Type the new name of the Screen Shot: " & shortName
set theButtonIfPressedTheRuleWillContinue to "Rename Screen Shot"
set theButtonIfPressedRuleAborts to "Skip File"
set theDialogTitle to "Advanced Hazel Renaming"

tell application "System Events"
   activate
   set theResult to (display dialog theDialogText with title theDialogTitle default answer "" buttons {theButtonIfPressedTheRuleWillContinue, theButtonIfPressedRuleAborts} default button 1 giving up after 60)
end tell

if (button returned of theResult) is theButtonIfPressedTheRuleWillContinue then
   set theText to text returned of theResult
   return {hazelExportTokens:{NewFilename:theText}}
end if

return {hazelExportTokens:{NewFilename:shortName}}

enjoy!
EnriqueO
 
Posts: 1
Joined: Wed Sep 05, 2012 5:53 pm

Re: Prompt to Rename Files Fri Jan 10, 2014 11:01 am • by CHoorel
Thank you so much for this script. I use it almost every day.

I wonder if you are able to help me with the next step, since its outside my realm of knowledge. I would like to have a second prompt, after I rename the file, to ask me where I want to save the file. I am constantly having to move the file after I rename it, and I would love to automate it.

I am sure it involves applescript, which I know nothing about. Any ideas?

Thank you!
CHoorel
 
Posts: 1
Joined: Fri Jan 10, 2014 10:58 am

Re: Prompt to Rename Files Tue Aug 02, 2016 4:27 am • by Ruby
murr wrote:when i run the rule now, the pop up shows, i rename the file, click the button and nothing happens. the filename is the same as it was. the log file doesn't have any info to assist either.

Hi, I realise it has been 4 years since this post was started, but I am having a similar problem and the only help I've received was a link to this post that I already had. I too know nothing about AppleScript. I've tried to follow this thread but it is difficult because all of the images are no longer visible. I don't even know if you are still a member on these forums or check them at all, but on the off-chance you do: here is a link to my post, I would be extremely grateful for any help you could offer:

https://www.noodlesoft.com/forums/viewt ... f=4&t=6991
Ruby
 
Posts: 7
Joined: Tue Jul 26, 2016 1:26 am

Re: Prompt to Rename Files Fri May 17, 2019 6:09 pm • by Stephen
The code in this thread (modified slightly for my needs below) works like a charm, and is super fast.

As a result of the speed, I wondered if anyone can advise me on the code I need to present a secondary confirmation screen before any changes are committed? I'd also like cancel option to return me to the main input screen if an error in the initial change is seen.


Code: Select all
## Working Code May 2019 ##
tell application "Finder" to set shortName to name of (theFile as alias)

set theDialogText to "Add New Details - Current Name: " & shortName
set theButtonIfPressedTheRuleWillContinue to "Rename This Image ?"
set theButtonIfPressedRuleAborts to "Skip Re-Naming ?"
set theDialogTitle to "Advanced Hazel Image Renaming"

tell application "Preview"
   activate
   open theFile
end tell

tell application "System Events"
   activate
   set theResult to (display dialog theDialogText with title theDialogTitle default answer shortName buttons {theButtonIfPressedTheRuleWillContinue, theButtonIfPressedRuleAborts} default button 1 giving up after 240 with icon (POSIX file (POSIX path of (get path to library folder) & "/PreferencePanes/Hazel.prefPane/Contents/Resources/Hazel.icns" as string) as string) as alias)
end tell

if (button returned of theResult) is theButtonIfPressedTheRuleWillContinue then
   tell application "Preview" to quit
   delay 0.8
   set theText to text returned of theResult
   return {hazelExportTokens:{NewFilename:"Go_ " & theText}}
   --return {hazelExportTokens:{NewFilename:theText}}
   
   
end if
tell application "Preview" to quit
delay 0.8
--return {hazelExportTokens:{NewFilename:shortName}}
return {hazelExportTokens:{NewFilename:"Stop_ " & shortName}}

Stephen
 
Posts: 7
Joined: Sun Jan 22, 2017 9:34 am

Re: Prompt to Rename Files Fri Nov 25, 2022 5:44 am • by steffb
Hello everybody

I tried all the apple scripts but I don't get it running, just with errors. Any news how go get this working. I'm using Hazel 5.2. I just want a prompt to rename the file name when a file is coming into the download folder with some rules.

Thanks. Stefan
steffb
 
Posts: 1
Joined: Fri Nov 25, 2022 5:39 am

Previous

Return to Support