I have an applescript studio project that counts the files in a watch folder and displays a progress bar while there are files in the folder. A completely different process that runs as root removes the files from the folder as each task is completed. As the tasks are completed the progress bar updates. In order to get the progress bars to work I put the code in the on idle handler, see below.
Now, I am trying to add a button to the application which will kill the process running as root. However, I believe that the idle handler is not allowing the on clicked handler to execute. Has anyone dealt with this or have any ideas how I could work around this?
-- teset.applescript
-- test
on idle theObject
set watchfolder to "myhd:watch:"
set the startingCount to countWatchfolder(watchfolder)
set content of text field "currentcount" of window "main" to startingCount as number
set content of text field "startingCount" of window "main" to startingCount
set maximum value of progress indicator "bar" of window "main" to startingCount
set content of progress indicator "bar" of window "main" to 0
set indeterminate of progress indicator "bar" of window "main" to false
start progress indicator "bar" of window "main"
start progress indicator "spinner" of window "main"
if startingCount is greater than 0 then
set visible of window "main" to true
else
quit
end if
set currentCount to countWatchfolder(watchfolder)
repeat until currentCount = 0
set currentCount to countWatchfolder(watchfolder) as number
set currentFile to getFileName(watchfolder)
set content of text field "currentcount" of window "main" to currentCount
set content of text field "fileName" of window "main" to currentFile
set processedCount to (startingCount - currentCount)
set content of progress indicator "bar" of window "main" to processedCount
end repeat
quit
end idle
on clicked theObject
if the name of theObject = "abortRequest" then
set theReply to display dialog "Are you sure you want to stop this request?" buttons {"No", "Yes"} default button 1 attached to window "main"
end if
end clicked
on dialog ended theObject with reply theReply
if button returned of theReply is equal to "Yes" then
killprocess()
end if
end dialog ended
on countWatchfolder(watchfolder)
set theFolderItems to list folder watchfolder without invisibles
set theCount to (count of theFolderItems) as number
return theCount as number
end countWatchfolder
on getFileName(watchfolder)
set master_file_list to list folder alias watchfolder without invisibles
set this_item to item 1 of master_file_list
set this_item_name_list to every character of this_item
set this_item_name to items 6 through -5 of this_item_name_list as string --display dialog this_item_name_list
return this_item_name
end getFileName
on killprocess()
do shell script "sudo killall taskApp" user name "admin" password "" with administrator privileges
end killprocess