I’m fairly new to applescripting, and i’ve been working on this script quite a while now, and I can’t seem to get it working. The script works perfectly when I specify it to one file, but it wont work with the “on adding folder items to”. this is the script:
on adding folder items to this_folder after receiving added_items
repeat with eachitem in added_items
tell application “TextEdit” to activate
tell application “TextEdit” to open added_items
tell application “System Events”
tell process “TextEdit”
keystroke “f” using command down
keystroke “(”
keystroke tab
keystroke “)”
click button “Replace All” of window “Find”
keystroke “w” using command down
keystroke “s” using command down
keystroke “w” using command down
end tell
end tell
end repeat
end adding folder items to
I tried specifying the folder but it didn’t help as well.
Model: Macbook
AppleScript: 2.2.1
Browser: Firefox 3.6.10
Operating System: Mac OS X (10.5)
as eachitem is your index variable, you should use it for processing the files one by one
tell application "TextEdit" to open eachitem
Note: If the added items are plain text files, TextEdit is not necessary to find and replace text.
AppleScript can do it itself with read/write and text item delimiters
Mhhmmm so a new problem comes up, I need to convert the JPG images to PNG. What I did was tell the altered images to be moved to another folder, and on that folder I made a script that converts them.
this script:
on adding folder items to this_folder after receiving added_items
repeat with eachitem in added_items
tell application “Image Events”
launch
set theImageReference to open eachitem
tell theImageReference
save in (this_folder as string) as PNG
beep
close
end tell
end tell
end repeat
end adding folder items to
problem is, it doesn’t start. Is this because the move command in the other script?
maybe you must specify the full path to the converted image.
But “renaming” in an hot folder can cause to trigger the folder action again.
If this happens you should filter png files by removing the two comment tokens (–)
on adding folder items to this_folder after receiving added_items
repeat with eachitem in added_items
set {name:Nm, name extension:Ex} to info for eachitem
if Ex is missing value then set Ex to ""
if Ex is not "" then set Nm to text 1 thru ((count Nm) - (count Ex) - 1) of Nm
-- if Ex is not "png" then
tell application "Image Events"
launch
set theImageReference to open eachitem
tell theImageReference
save in ((this_folder as text) & Nm & ".png") as PNG
beep
close
end tell
end tell
-- end if
end repeat
end adding folder items to
thanks allot! this works, but only when I drag and drop files onto the folder, it doesn’t work when the script moves the file into the folder, it doesn’t activate it because it’s not being dropped I guess… Should I combine the two codes?
Is there a way for the script to activate instead of “on adding folder items to” ?
Since the first applescript tells to move the files into the second folder, the action script on the second folder doesn’t activate because it’s not being dropped, I guess.