I have a Folder named HotFolder this contains images with a Sku the first 4 letters/numbers refer to the type of file it is.
For example. FR10xxxxxxxxxxxx.jpg (or .PSD)
TM10WWxxxxxxxxxxxx.jpg
I need to move this file to a folder on the desktop that is labelled FR_WK10 and TM_WK10, the number changes each week but the begin of each folder changes and is unique.
Any ideas how I can move the files FR to the folder begining with FR and the files TM to folder TM?
I tried on Automator but run into difficult after it filters out all others.
Any suggestions
(in case you weren’t away I have very limited applescript knowledge.)
For example Files begining with FR10 go into folder on desktop beginning with Fr (where the folder name is free_WK10) These folders will already exist and just need move from on folder to another. I then need to repeat the code for all other files in the folder.
on adding folder items to thisFolder after receiving newItems
set thisFolder to thisFolder as string
set delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" on "}
repeat with i from 1 to (count of newItems)
set currItem to item i of newItems
tell application "Finder"
set itemName to name of currItem
if ((count of text items of itemName) > 1) then --Otherwise non-standard name, do nothing
set personName to first text item of itemName
set newFileName to second text item of itemName
set folderForFile to thisFolder & personName & ":"
if not (exists folder folderForFile) then
make new folder at alias thisFolder with properties {name:personName}
end if
set name of currItem to newFileName
set currItem to file (thisFolder & newFileName)
move currItem to folder folderForFile
end if
end tell
end repeat
set AppleScript's text item delimiters to delim
end adding folder items to
error “Finder got an error: Can’t make folder "Burgess2do_WK15_to_do" of folder "Desktop" of folder "Username" of folder "Users" of startup disk into type integer.” number -1700 from folder “Burgess2do_WK15_to_do” of folder “Desktop” of folder “Username” of folder “Users” of startup disk to integer
tell application "Finder"
set desktopFolder to folder "Macintosh HD:users:username:Desktop"
set desktopFolderList to every folder of desktopFolder
repeat with x in the desktopFolderList
if name of x starts with "Burgess2do" then
set FolderA to x
end if
end repeat
set theHotFolder to folder "Macintosh HD:users:username:HotFolder Copy"
set the_FileList to every file of theHotFolder
repeat with i in the_FileList
if name of i starts with "BU" then
move i to folder FolderA
end if
end repeat
end tell
Start simple – groping for some code doesn’t help if you don’t have a plan. Here’s an example where I choose folders to get their locations, grab the first three
set HotFolder to choose folder with prompt "Choose the Hot Folder" -- result is an alias to the hot folder.
set TargetFolder to choose folder with prompt "Choose the Target Folder" -- result is an alias to the target folder
tell application "Finder"
-- get the first three characters of the target folder's name
set ScreenCode to (characters 1 thru 3 of (name of TargetFolder)) as text
set AllFiles to files of HotFolder as alias list
repeat with oneFile in AllFiles
if name of oneFile starts with ScreenCode then move contents of oneFile to TargetFolder
end repeat
end tell
I didn’t test this, but you’ll see the logic of it. “contents of oneFile” is not the contents of the file, it’s a way to extract the real location from the reference to it in “oneFile”.
using your example, this works for me, but i am sure there is a better way
set desktopFolder to path to desktop folder
tell application "Finder"
set desktopFolderList to every folder of desktopFolder
repeat with x in the desktopFolderList
if name of x starts with "Burgess2do" then
set FolderA to x
end if
end repeat
set theHotFolder to folder (desktopFolder & "HotFolder Copy" as text)
set the_FileList to every file of theHotFolder
repeat with i in the_FileList
if name of i starts with "BU" then
move i to folder (FolderA as text)
end if
end repeat
end tell