Q: Renaming process with applescript/automator
Hi
I need an automater workflow or an applescript that will watch a folder called “Finished videos”. When a video file (.mkv or .mp4) gets added to this folder, it should do the following:
- Create a new folder in the “Finished videos” folder
- Rename the new folder identical to the file that was added (minus the extension)
- Copy the added file into this new folder
- Delete the added file so it ONLY exists in the new renamed folder.
Alternatively if it is easier, it would be ok if the new folder gets created in a different “destination” folder. As long as the video file ends up in a folder named idental to itself.
No prompts should be shown during the process. It needs to run automataically.
Is this even possible? Hope someone can help :-)
Kind regards
Jesper
MacBook Pro with Retina display, OS X El Capitan (10.11.4)
Posted on Sep 13, 2016 5:51 AM
Since you asked (or, at least, I inferred you were asking for) a Folder Action, you should save this script in your Folder Action Scripts folder in ~/Library/Scripts/
Then, find the folder that you want it to watch, ctrl-click the folder and choose Folder Actions Setup from the Services menu.
From here you can see the folders that have Actions assigned (it may be a very short list). Select your folder and then click the + button below the list of active scripts on the right-hand-side. You should see a list of installed Folder Actions Scripts, including the one you just saved. Select it, and you're done. Dropping a file into this folder should now trigger the script.
A thought did just occur to me, though, that the script might need a little more sanity checking. Since the script creates a new folder to move the file into, the script could re-fire as the new folder looks like a new item that needs to be filtered/moved. An additional check to make sure the dropped file is, indeed, a file that needs to get moved would be a good idea. This updated version ensures the script only triggers on documents, not folders:
on adding folder items to theFolder after receiving theNewItems
repeat with eachItem in theNewItems
tell application "Finder"
if class of eachItem is document file then
set theBaseName to my getBaseNameOf(eachItem)
set theNewFolder to make new folder at theFolder with properties {name:theBaseName}
move eachItem to theNewFolder
end if
end tell
end repeat
end adding folder items to
on getBaseNameOf(thisItem)
tell application "Finder"
set ext to name extension of thisItem
set extLength to number of characters in ext
set n to characters 1 through -(extLength + 2) of (get name of thisItem) as text
end tell
return n
end getBaseNameOf
Posted on Sep 19, 2016 6:12 AM