Automator - assign random numbers to file…
apple Verified ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
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
11 replies
Sign in or join Beachball Help to reply.
- 0
EShaver102 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
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.
- 0
TheZiggy ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
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
- 0
daylerenee ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
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
- 0
Niel ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
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 tellThe range of random numbers can be changed as needed.
(40211)
- 0
matttayres ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
thanks! worked perfectly.
- 0
sknowlton ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
yeeeeeaaaaaaaahhh..... except when you have your application folder open as your forefront folder when you run it... mmmm... gonna be a long night.
- 0
red_menace ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
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
- 0
iMac39 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
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?
- 0
TechAddict ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
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!!!
- 0
BDAqua ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi, likely something has changed since 10.5.x, I'd start a new thread in whatever OSX version you are using. 🙂
- 0
daylerenee ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Nevermind. I was missing a step and it worked. Thank you very much!