Hi
I have a program which aquires an image, and display the image as it is aquired in a window. I worte a script that would pause the script until a certian file size was changed, but this only worked if the pciture was auto saved. But how do I tell the script to pause until the window is done acuiring the image. I was thinking something along the lines of “pause until there in no front panel activity.”
Thanks,
Adam
You don’t say what the program acquiring the image is, so it’s impossible to say.
The program is called “Revolution” I was trying to find a temp file that it wrote the image to, and was going to add the “file size” code. No temp file exist, that approach failed. Is it possible to write something along the lines of "while this program is still busy that pause a certain amount of time and check its status again?
Thanks,
Adam
Looking at the Revolution site, I doubt very much that Revolution is scriptable. When you look at the Revolution window during a download, how do you know when it’s finished? Does the title of it’s window change, for example? Is the cursor different?
There is a timer on the Revolution program that gives you an exact count down until the image is done. The only problem is that the timer changes based on the different types of pictures taken. The script I have written pause for a given time, based on input from the user. I just thought if I could make it more stable if I programically check to see if it was done. I don’t think there is anyway to access the timer built into the Revolution software.
Thanks,
Adam
Is the timer a progress bar? If it is, you could check for the presence of that window.
the timer just counts down to 0. I think I found some code that might work, but I could not incorporate it into my code. For some reason, I keep getting a “expected else, etc. but found on” error. Here is what I have so far.
/start of code
tell application “Extra Suites”
delay 1
ES move mouse {142, 58}
ES click mouse with click
delay 1
my isAppBusy("Revolution 1.6.0b146")
on isAppBusy(theApp)
set theApp to text 1 thru 10 of theApp
set placementOffset to my CountItem(theApp, " ") as integer
set thePlace to placementOffset + 3 as string
set theCheck to do shell script "top -R -s 2 -l 2 | awk '/" & theApp & "*/ {busy= $" & thePlace & "}; END {print busy}'"
set theCheck to my replace_chars(theCheck, "%", "")
if (theCheck = "") then
set theCheck to 0
else
set theCheck to theCheck as real
end if
-- If the app is using less than 2% of the processor it is probably not really busy
if (theCheck is less than 2) then
return false
else
return true
end if
end isAppBusy
on replace_chars(this_text, search_string, replacement_string)
set AppleScript’s text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript’s text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript’s text item delimiters to “”
return this_text
end replace_chars
on CountItem(txt, Itm)
set text item delimiters of AppleScript to Itm
set Nbr to (count (text items of txt)) - 1
set text item delimiters of AppleScript to “”
return Nbr
end CountItem
/End of code
tell application "Extra Suites"
delay 1
ES move mouse {142, 58}
ES click mouse with click
delay 1
end tell -- <-- Add this
my isAppBusy("Revolution 1.6.0b146")
I can’t believe I missed that, now I feel stupid. Thanks for the info. When I try and add this code into a repeat command, I get the expected “end” but found “on”. Is it not possible to use the “on” command in a repeat statement. I added the tell Finder part as debugging.
/Start of code
set hi to false
repeat until hi is true
my isAppBusy("Safari")
--my isAppBusy("Revolution 1.6.0b146")
on isAppBusy(theApp)
set theApp to text 1 thru 10 of theApp
set placementOffset to my CountItem(theApp, " ") as integer
set thePlace to placementOffset + 3 as string
set theCheck to do shell script "top -R -s 2 -l 2 | awk '/" & theApp & "*/ {busy= $" & thePlace & "}; END {print busy}'"
set theCheck to my replace_chars(theCheck, "%", "")
if (theCheck = "") then
set theCheck to 0
else
set theCheck to theCheck as real
end if
-- If the app is using less than 2% of the processor it is probably not really busy
if (theCheck is less than 2) then
return false
else
return true
end if
end isAppBusy
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
on CountItem(txt, Itm)
set text item delimiters of AppleScript to Itm
set Nbr to (count (text items of txt)) - 1
set text item delimiters of AppleScript to ""
return Nbr
end CountItem
end repeat
–end
/End of code
Thanks,
Adam
No it’s not possible to put handlers into repeat loops - they must stand alone at the top level of the script or within a script object at the top level of the script. Only the call goes in the loop.
NOTE: when you move the ‘end repeat’ up under isAppBusy(“Safari”) where you don’t need the ‘my’, don’t run it! How will ‘hi’ ever get to be true? What you need in the loop is ‘set hi to isAppBusy(“Safari”)’
By the Way: you might want to think about the possibility that the expected operation will never happen. Something like this:
set hi to false
set c to 0
repeat until hi is true
set hi to isAppBusy("Safari")
set c to c + 1
delay 1
if c > 10 then display dialog "The application is not responding" with icon 0 buttons {"Cancel"} default button 1
end repeat
display dialog "Shouldn't be able to get here"
on isAppBusy(myApp)
return false
end isAppBusy
I tried the code above and it worked fine, until “Safari” was done loading. It did not exit the if statement. I changed the script to display a message, delaying .5 seconds, to show the status of “Safari.” I put this code together, but can not get it to display the message. It is supposed to display the message after the script detects the program is using less then 2.0% processor. I can see it using the percentage of the procesor, under the event log. I set hi to false, beccause I want the script to run forever until I stop it. Also, on my computer, it takes about 2 or 3 seconds for the script to run, and I have to use “commad .” to stop the script. Have you ever encountered this same problem?
/Start of code
set hi to false
repeat until hi is true
my isAppBusy(“Safari”)
end repeat
on isAppBusy(theApp)
–set theApp to text 1 thru 10 of theApp
set placementOffset to my CountItem(theApp, " ") as integer
set thePlace to placementOffset + 3 as string
set theCheck to do shell script “top -R -s 2 -l 2 | awk '/” & theApp & “*/ {busy= $” & thePlace & “}; END {print busy}'”
set theCheck to my replace_chars(theCheck, “%”, “”)
if (theCheck = “”) then
set theCheck to 0
else
set theCheck to theCheck as real
end if
-- If the app is using less than 2% of the processor it is probably not really busy
if (theCheck is less than 2) then
return false
display dialog "hi"
else
return true
end if
end isAppBusy
on replace_chars(this_text, search_string, replacement_string)
set AppleScript’s text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript’s text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript’s text item delimiters to “”
return this_text
end replace_chars
on CountItem(txt, Itm)
set text item delimiters of AppleScript to Itm
set Nbr to (count (text items of txt)) - 1
set text item delimiters of AppleScript to “”
return Nbr
end CountItem
end
/End of code
Thanks,
Adam
Again, hi will never be true because you don’t set it in the calling loop.
The display dialog hi will never happen either, because it’s after the return instead of before - the handler never gets there, it returns as you asked it to.
When you’re posting a reply, you’ll see just above the reply text box the button “AppleScript”. Select your script (not the whole message) and click on that button. You’ll see the script in your reply is now in between bracketed labels, and when you preview or look at the post, it will have an “Open this scriptlet in your Editor” link above it. If you click on that link, it will open the contents in your script editor. Makes it a hell of a lot easier to help you if you do the same - I just click on the link and the script is in my script editor ready to deal with - I don’t have to copy and paste. Do it from now on, please.