Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automator - assign random numbers to file names

Hi,

I have a digital photo frame. Unfortunately it doesn't have a 'random' setting, and therefore my photos all play in sequence.

The second best thing would be to assign a random number to my photos before I transfer them to the photo frame!

Would someone be able to advise how I could set up an automator process to do this?

Thanks in advance!

Matt

MacBook Pro 15", Mac OS X (10.5.6)

Posted on Jan 20, 2009 6:03 AM

Reply
11 replies

Jan 4, 2017 6:52 AM in response to iMac39

This is a HUGE bump... but my solution was to bulk rename all the files back to a pic(sequential order), then increase the scripts range of numbers. It's a random generator, yes, and it doesn't create an exclusion list of numbers already used, but what you can do is decrease the likelihood of duplicated numbers by increasing the range between the lower and upper values of the random numbers. I went from 10,000 range to 1,000,000 range. Running the script 2x, I got no duplicate errors. If you want to tidy the names up afterwards, if you select all the files within the folder, and rename all the files, there is an option to format all the files with a name, and then counter. Personally, I've made my prefix 'DCM_', as per typical photography format.

Oct 25, 2017 9:33 PM in response to EShaver102

A slightly improved solution that avoids needing to re-run for duplicate error:


tell application "Finder" to set this_folder to get every file of folder (choose folder with prompt "Select folder containing files to rename:")


set countVar to 0

repeat while countVar < (count of this_folder)

set countVar to countVar + 1

set this_item to item countVar of this_folder

nameFile(this_item)

end repeat


return (countVar & " Files Randomly Renamed.") as string


on nameFile(this_item)

try

tell application "Finder" to set name of this_item to ("img_" & (random number from 10000000 to 99999999) & "." & name extension of this_item) as string

on error

nameFile(this_item)

end try

return true

end nameFile

Nov 1, 2017 7:14 AM in response to TheZiggy

Thank you for your patience in advance. I have never used script editor and I have no programing skills what-so-ever! I would really like to make this work though. I copy and pasted your script above exactly how it was written in script editor:


tell application "Finder" to set this_folder to get every file of folder (choose folder with prompt "Select folder containing files to rename:")


set countVar to 0

repeat while countVar < (count of this_folder)

set countVar to countVar + 1

set this_item to item countVar of this_folder

nameFile(this_item)

end repeat


return (countVar & " Files Randomly Renamed.") as string


on nameFile(this_item)

try

tell application "Finder" to set name of this_item to ("img_" & (random number from 10000000 to 99999999) & "." & name extension of this_item) as string

on error

nameFile(this_item)

end try

return true

end nameFile


I saved it and then ran it and nothing happened. If I have a folder named Slideshow where the photos are saved that I want renamed. Do I have to indicate that folder name in the script somewhere? I am sorry, I am asking such basic questions and appreciate any help you can provide.


Dayle

Jan 20, 2009 7:12 PM in response to matttayres

Place all the photos in one folder, launch the Script Editor in the /Applications/AppleScript/ folder, and run the following with that folder in the frontmost Finder window:

tell application "Finder"
repeat with this_item in (get items of window 1)
set name of this_item to ((random number from 1000 to 9999) & "." & name extension of this_item) as string
end repeat
end tell

The range of random numbers can be changed as needed.

(40211)

Jun 6, 2009 9:18 PM in response to sknowlton

The script also doesn't work if there isn't a Finder window open. It won't help you now, but it would be a little bit safer to use something like:

repeat with this_item in (get document files of (choose folder with prompt "Select a folder containing files to rename:"))

I suppose it could have been worse - at least it didn't recurse into subfolders (I don't even want to think about that with a folder full of applications). Of course, if you had been running from a standard account instead of an administrative one... ;p

Mar 9, 2012 1:54 PM in response to Niel

Thank you very much.. this was very helpful..


Unfortunately, it stoped a number of times because of duplicate file names. I have to manuall rename the file and restart the script for each error.


I am not an apple scripter, but can this be modified to check if the next random number has already been used, and if so, assign a new random number.. and iterate this until a unused number is found?

Dec 22, 2015 9:50 PM in response to iMac39

Old thread. Trying to do this myself. Sounds easy but I'm confused.


I put the pics in a folder. I then run Script Editor. But it opens up in iCloud and asks me to create a new document. I don't want to! Simply want to random rename a bunch of photos. But I can't seem to find a way to be sure that I'm telling SE what to do. Nor how I have to make sure I rename just that folder and not a bunch of apps or system files. SE doesn't even seem to actually show you what folder it's going to work with. I don't seem to be able to actually DO anything with Script Editor except create a new document. Can select and folders / files anything. Or is new document Apple speak for doing something????


As with everything Apple. Difficult!!!

Automator - assign random numbers to file names

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.