Re: Moving Files in a Folder to Another Folder
Re: Moving Files in a Folder to Another Folder
- Subject: Re: Moving Files in a Folder to Another Folder
- From: Doug McNutt <email@hidden>
- Date: Sun, 20 Jan 2013 05:01:49 -0700
At 11:14 +0100 1/20/13, koenig.yvan wrote:
>Le 20/01/2013 à 07:54, dealTek <<mailto:email@hidden>email@hidden> a écrit :
>
>>Hi all,
>>
>>I'm fooling with a folder actions script - sort of works but does not always trigger sometimes a few seconds sometimes longer and some items that meet criteria don't get moved.
>>
>>often items will get added to the main folder sometimes 1 per second or sooner...
>>
>>Q1: Is there a way to get this to always trigger properly?
>>
>>Q2: also - I'd like to set this up without using folder actions - and just start a normal applescript that will repeat with each item in the folder and move it all at once - how would I go about making that script
>>
>>--------------------------
>>
>>folder actions script ........
>>
>>on adding folder items to this_folder after receiving added_items
>>
>> repeat with i in added_items
>> tell application "Finder" to if (name of i) contains ".htm" then move i to "drive1:folderstuff:f1"
>> tell application "Finder" to if (name of i) contains ".txt" then move i to "drive1:folderstuff:f2"
>> tell application "Finder" to if (name of i) contains ".jpg" then move i to "drive1:folderstuff:f3"
>> end repeat
>>
>>end adding folder items to
>>
>
>(1) I never loop upon added_items.
>I loop upon the contents of the folder
>
>(2) using do Shell Script we may move a group of files in a single call.
>
>So I would use :
>
>on adding folder items to this_folder after receiving added_items
> set lesParams to {{".htm", "drive1:folderstuff:f1"}, {".txt", "drive1:folderstuff:f2"}, {".jpg", "drive1:folderstuff:f3"}}
> repeat with i from 1 to count lesParams
> tell application "System Events"
> set lesFichiers to (path of every file of this_folder whose name ends with item 1 of item i of lesParams)
> end tell
> set lesFichiersqp to {}
> repeat with unFichier in lesFichiers
> set end of lesFichiersqp to quoted form of POSIX path of unFichier
> end repeat
> set lesFichiersqp to my recolle(lesFichiersqp, space)
> do shell script "mv " & lesFichiersqp & space & quoted form of POSIX path of item 2 of item i of lesParams
> end repeat
>end adding folder items to
>
>#=====
>
>on recolle(l, d)
> local oTIDs, t
> set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
> set t to "" & l
> set AppleScript's text item delimiters to oTIDs
> return t
>end recolle
>
>#=====
It continues to amaze me just how efficiently Applescript can make simple things a PITA.
Put these lines in a text file and store it anywhere.
cd . . . full path to the folder actions directory you want to use.
mv *.htm /Volumes/drive1/folderstuff.f1/
mv *.txt /Volumes/drive1/folderstuff.f2/
mv *.jpg /Volumes/drive1/folderstuff.f3/
Then write a one line Applescript and "do shell script" to execute the stored file whenever you poke a button.
Request the details you need about the mv command with a "man mv" command in terminal.app. The * in the filenames is a globbing character that represents any string of characters. It also will use just filenames that END with the suffixes rather than find them anywhere in the filename. You could add a * like this:
mv *.htm* /Volumes/drive1/folderstuff.f1/
to get the exact results that your Applescript would perform and do the right thing for somefile.html and somefile.jpeg.
You could also add the full path to the targeted directory before the first asterisk of each line.
--
Applescript syntax is like English spelling:
Roughly, though not thoroughly, thought through.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden