I’m trying to make this script run in the background and upload files to a server when they’re added to a folder. Unfortunately it just ends without doing anything at all, so I must be doing the “on idle” stuff wrong. If I remove it, it works pretty much the way I want it to. Can anyone help me figure out what I’m doing wrong? There must be some fundamental thing I’m missing in my script.
global theWatchedFolder
on run
set theWatchedFolder to "Mac HD:Users:pp:Main:jlist:upload" as alias
set thefolder to "f5"
end run
on idle
tell application "Transmit"
set thedocs to every document
end tell
tell application "Finder"
set theDetectedItems to every item of theWatchedFolder
if length of theDetectedItems is not 0 then
tell application "Transmit"
set theWindow to name of window 0
end tell
if theWindow = "images.jlist.com - html" or theWindow = ("images.jlist.com - " & thefolder) then
-- do nothing, already open
else
-- starting the new script
-- opening connection with Transit
set theServerAddress to "aserver.com"
set theUserName to "images"
set thePassword to "-------"
set theDirectory to "html/"
tell application "Transmit"
set theDocument to make new document with properties {name:theServerAddress}
tell theDocument
tell current session
connect to theServerAddress as user theUserName with password thePassword with initial path theDirectory
end tell
end tell
end tell
end if
repeat with aDetectedItem in theDetectedItems
set thename to name of aDetectedItem
set file1 to "Mac HD:Users:pp:Main:jlist:upload:" & thename as alias
tell application "Transmit"
tell document 1
tell current session
set their stuff to "/html/" & thefolder & "/"
upload item file1 with resume mode replace
end tell
end tell
end tell
end repeat
tell application "Transmit"
tell document 1
close
end tell
end tell
end if
end tell
return 5
end idle
Model: Mac Pro
AppleScript: 2.2
Browser: Safari 523.10
Operating System: Mac OS X (10.5)