i want to write an applescript with a folder action that resizes and copies image sequences from one folder to another one.
I came up with the automatization of the folder action, it starts when a file gets in the folder, that’s ok.
The image sequences will be in DPX format, so i will use “do shell script” with ImageMagick or NConvert or something like that to resize and copy images, that’s kinda ok too.
The input directory will be flooded with subdirectories, i came up with a way for folder action to work with subdirectories, so i think that’s ok too.
Where i’m stuck at is:
Let’s say that the input folder is: startup disk/folder1/folder2/FullRes/folder3/folder4/folder5/
I want the destination folder to be: startup disk/folder1/folder2/Proxy/folder3/folder4/folder5/
I think it has something to do with the POSIX path, i guess i should get the path and change a portion of it, but how?
P.S. just now i found out the “path to list” thing, is that the way?
Here is a simple search and replace handler from another post in the forum:
-- You probably already have the path in a variable, so just use that.
set fullres_path_string to "Path To:Folder:FullRes:And:Beyond:"
display alert "Proxy path is " & fullres_path_string as informational
set proxy_path_string to simpleReplace("FullRes", "Proxy", fullres_path_string)
display alert "Proxy path is " & proxy_path_string as informational
(*
simpleReplace() handler from
http://bbs.applescript.net/viewtopic.php?pid=66284#p66284
For a multiple target/replacement version, see
http://bbs.applescript.net/viewtopic.php?pid=39314#p39314
*)
on simpleReplace(search, replace, subject)
local search, replace, subject, ASTID
set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to search
set subject to text items of subject
set AppleScript's text item delimiters to replace
set subject to "" & subject
set AppleScript's text item delimiters to ASTID
return subject
end simpleReplace
Since it is just a normal string search and replace, it will work with either normal Mac OS paths (colon delimited) or POSIX paths (forward slash delimited, with a leading forward slash).
To use the simpleReplace() handler, you’ll need to have your “FullRes” path as a string. path to list might be what you need, it depends on what your list is. Some objects have path properties that are strings. Most objects have path properties that are aliases though (the AppleScript kind, not the Finder kind). If you need to convert an alias to a string, you can say var_with_alias as string to get the “path-with-colons”, or POSIX path of var_with_alias to get the “path-with-slashes”.
From string to string:
-- string already in fullres_path_string
set {fullres_string, proxy_string} to {"FullRes", "Proxy"}
set proxy_path_string to simpleReplace(fullres_string, proxy_string, fullres_path_string)
-- proxy_path_string now ready for use
From FullRes alias to Proxy alias:
-- alias already in fullres_alias
set {fullres_string, proxy_string} to {"FullRes", "Proxy"}
set fullres_path_string to fullres_alias as string
set proxy_path_string to simpleReplace(fullres_string, proxy_string, fullres_path_string)
set proxy_alias to alias proxy_path_string
-- proxy_alias now ready for use
From FullRes Finder item to Proxy Finder item:
-- Finder item already in fullres_Finder_item
set {fullres_string, proxy_string} to {"FullRes", "Proxy"}
set fullres_path_string to fullres_Finder_item as string
set proxy_path_string to simpleReplace(fullres_string, proxy_string, fullres_path_string)
tell application "Finder" to set proxy_Finder_item to item proxy_path_string
-- proxy_Finder_item now ready for use
Note: Both aliases and Finder items can only reference already existing items. This means that the folders and/or file named by the new string (the “Proxy” path) must exist before the last set command executes. If they do not exist yet, but something else is going to use the path string to create the items, then just leave off the last set command and pass proxy_path_string along to whatever is going to use the path-with-colons that is stored there.