i have made a script to put files in a folder,shows a dialog, give it a name to make a new folder and then move it to another folder with the items. I use the handler “on adding” but the dialogwindow repeating itself again and i do not know how stop this.
What do i do wrong ???
on adding folder items to thisFolder after receiving addedItems
repeat with anItem in addedItems
tell application “Finder”
activate
display dialog “Enter Order nummer” with icon caution �
default answer “”
copy the result to myReSult
if the button returned of myReSult is “OK” then
set propertie to the text returned of myReSult
tell application “Finder”
activate
set my_folder to make new folder at folder “Advertentie’s” of desktop with properties {name:the text returned of myReSult}
tell application “Finder” to set fileList to every file of folder “Advertentie’s”
move the fileList to my_folder
tell application “Finder”
move my_folder to folder “Dolf HD:Advertenties in:”
end tell
end tell
end if
end tell
end repeat
end adding folder items to
The following happens, when i put some items in de watchedfolder the script makes
a new folder with a ordernumber. (wich i enter in the dialog window before) and put in the items wich i added and then the new folder moves to another folder till then
it works well, but then the script shows “again” a dialog window with the same question
(enter a ordernumber) while the script already did what it wanted and this i do not want because de new folder is already gone. so the script ask me two or more times
to make a new folder this depends how many items i added. it keep repeating to ask
me to make a new folder.
on adding folder items to thisFolder after receiving addedItems
display dialog “Enter Order nummer” with icon caution ¬
default answer “”
copy the result to myReSult
if the button returned of myReSult is “OK” then
set propertie to the text returned of myReSult
end if
repeat with anItem in addedItems
tell application “Finder”
activate
set my_folder to make new folder at folder “Advertentie’s” of desktop with properties {name:the text returned of myReSult}
set fileList to every file of folder “Advertentie’s”
move the fileList to my_folder
move my_folder to folder “Dolf HD:Advertenties in:”
end tell
end repeat
end adding folder items to
this is your own script. I only set the “display dialog” out of the repeat statement and
you were calling too much the Finder. One call is enough.
Yes Rob this script is attached to the folder “Advertentie’s” and i removed the repeat loop but still an second dialogbox “Enter Order nummer” appears. I also used the the second thought to move the repeat code but again the dailogbox is there again ??? it seems that
the “on adding” code notice that there is a second “thing” in the folder, mayby the
new folder ???
Yes, it notice that your new folder is added.
I don’t know if it’s exactly what you want , but this works :
on adding folder items to thisFolder after receiving addedItems
display dialog "Enter Order nummer" with icon caution ¬
default answer ""
copy the result to myReSult
if the button returned of myReSult is "OK" then
set propertie to the text returned of myReSult
end if
tell application "Finder"
activate
set my_folder to make new folder at folder "Advertentie's in" of desktop with properties {name:the text returned of myReSult}
set fileList to every file of folder thisFolder
move the fileList to my_folder
end tell
end adding folder items to
Yes, I would use a folder other than the one with the folder action so that the newly created folders don’t trigger the folder action. This should solve the problem.
Does this work? During testing, it ignored folders that were created by the script but it will fail if only a folder is added to the attached folder.
on adding folder items to thisFolder after receiving addedItems
repeat with item_ in addedItems
if folder of (info for item_) is false then
set myReSult to (display dialog "Enter Order nummer" with icon caution ¬
default answer "")
if the button returned of myReSult is "OK" and ¬
text returned of myReSult is not "" then
set propertie to the text returned of myReSult
else
if the button returned of myReSult is "OK" and ¬
text returned of myReSult is "" then
display dialog "No folder name was entered!" buttons ¬
{"OK"} default button 1 with icon 0
error number -128 -- terminate further execution
end if
end if
tell application "Finder"
activate
try
set my_folder to (make new folder at ¬
thisFolder with properties {name:propertie})
on error e
display dialog e buttons {"OK"} default button 1 with icon 0
error number -128 -- terminate further execution
end try
move addedItems to my_folder
end tell
exit repeat
end if
end repeat
end adding folder items to
I think i solved the problem by using a third folder and it’s works.
at first i made this code to put the files or folder somewhere.
on adding folder items to thisFolder after receiving addedItems
repeat with anItem in addedItems
tell application “Finder”
activate
move every file of folder “Dolf HD:Desktop Folder:Werkmap: ADVERTENIE ZONDER:” to folder ¬
“Dolf HD:Desktop Folder:TF:”
move every folder of folder “Dolf HD:Desktop Folder:Werkmap: ADVERTENIE ZONDER:” to folder ¬
“Dolf HD:Desktop Folder:TF:”
end tell
exit repeat
end repeat
end adding folder items to
Then i do the job in another folder
on adding folder items to thisFolder after receiving addedItems
tell application “Finder”
display dialog “Enter Order nummer” with icon caution ¬
default answer “”
copy the result to myReSult
if the button returned of myReSult is “OK” then
set propertie to the text returned of myReSult
set my_folder to (make new folder at folder “TF:” of desktop with properties ¬
{name:the text returned of myReSult})
if exists items in folder “TF” then
set theFolderList to folder “Dolf HD:Desktop Folder:TF:”
set theNameList to “”
repeat with thisItem in theFolderList
set theNameList to (the name of thisItem)
move item (the name of thisItem) of folder “Dolf HD:Desktop Folder:TF:” to my_folder
set label index of my_folder to 1
move my_folder to folder “Dolf HD:Desktop Folder:Werkmap: ADVERTENTIE MET:”
exit repeat
end repeat
end if
end if
end tell
end adding folder items to
maybe it’s not it, but it is working for me, any comment is welcome.
Here’s a slightly modified version of your second script. It simply requires that something is actually entered in the dialog if the OK button is chosen.
on adding folder items to thisFolder after receiving addedItems
tell application "Finder"
repeat -- make sure that something is entered in the dialog
set myReSult to (display dialog "Enter Order nummer" with icon caution ¬
default answer "")
if text returned of myReSult is not "" then exit repeat
end repeat
if the button returned of myReSult is "OK" then
set propertie to the text returned of myReSult
set my_folder to (make new folder at folder "TF:" of desktop with properties ¬
{name:the text returned of myReSult})
if exists items in folder "TF" then
set theFolderList to folder "Dolf HD:Desktop Folder:TF:"
set theNameList to ""
repeat with thisItem in theFolderList
set theNameList to (the name of thisItem)
move item (the name of thisItem) of folder "Dolf HD:Desktop Folder:TF:" to my_folder
set label index of my_folder to 1
move my_folder to folder "Dolf HD:Desktop Folder:Werkmap: ADVERTENTIE MET:"
exit repeat
end repeat
end if
end if
end tell
end adding folder items to
on adding folder items to thisFolder after receiving addedItems
tell application "Finder"
activate
move entire contents of folder "Dolf HD:Desktop Folder:Werkmap: ADVERTENIE ZONDER:" to folder ¬
"Dolf HD:Desktop Folder:TF:"
end adding folder items to
N.B. : in your second script, you don’t need “exit repeat” before “end repeat”( and it’s confusing).
Debloem