Display dialog, await user input how to get no timeout?
I have a script i run on login, it brings up a dialog that requests user input, how can I stop it timing out if nothing happens?
iMac, Mac OS X (10.6.8)
You can make a difference in the Apple Support Community!
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
I have a script i run on login, it brings up a dialog that requests user input, how can I stop it timing out if nothing happens?
iMac, Mac OS X (10.6.8)
When you add a giving up after parameter to the display dialog command, the result includes a gave upkey in the returned result, i.e.
display dialog"whatever"giving up after20
--> {button returned:"OK", gave up:false}
... so your later button tests are failing. You should just be checking against a particular key (button returned) of the result instead of the entire returned result (which is actually a record with various keys/values).
When you add a giving up after parameter to the display dialog command, the result includes a gave upkey in the returned result, i.e.
display dialog"whatever"giving up after20
--> {button returned:"OK", gave up:false}
... so your later button tests are failing. You should just be checking against a particular key (button returned) of the result instead of the entire returned result (which is actually a record with various keys/values).
I have the same problem, and tested both of pjdube's suggestions.
tell application "Finder"
activate
with timeout of 300 seconds
display dialog "testing…" buttons {"OK"} default button "OK"
end timeout
end tell
worked but resulted in an error dialog when the timeout expired.
tell application "Finder"
activate
display dialog "testing…" buttons {"OK"} default button "OK"giving up after 300
end tell
timed out with an error dialog at 120 seconds, per my previous experience.
tell application "Finder"
activate
with timeout of 301 seconds-- must be longer than the "giving up" delay
display dialog "testing…" buttons {"OK"} default button "OK"giving up after 300
end timeout
end tell
worked and the dialog went away cleanly at 300 seconds. This is what I will now use.
Your problem is the Finder tell block. use Display Dialog outside of the Finder tell block and it works as expected.
This is good scripting practice anyway: best to use osax command (like display dialog) ouside of application tell blocks. It removes the possibility of errors of this sort.
twtwtw wrote:
Your problem is the Finder tell block. use Display Dialog outside of the Finder tell block and it works as expected.
This is good scripting practice anyway: best to use osax command (like display dialog) ouside of application tell blocks. It removes the possibility of errors of this sort.
Thanks. That works fine if Display Dialog is run by itself, but I can't get something like the following script to run properly, either from Script Debugger or from an applescript app. It beeps and the dialog will not appear until the the app it was run from is in front. Hence the need to run it inside a tell block. What am I missing?
tell application "Safari" to activate
delay 1
display dialog "testing…" buttons {"OK"} default button "OK" giving up after 150
If I am not mistaken, you want the dialog box to pop up first right? And then activate Safari right?
If so, this works:
display dialog "testing…" buttons {"OK"} default button "OK" giving up after 150
set site_url to "http://www.apple.com"
tell application "Safari"
activate
open locationsite_url
end tell
There's a trick you can try (one I haven't tested, but it should work). Put the display dialog in a handler so that it's no longer in the application's scope.
tell application "Safari"
activate
my displayMe()
end tell
on displayMe()
display dialog "testing…" buttons {"OK"} default button "OK" giving up after 150
end displayMe
red_menace wrote:
You just need to tell your application to activate before displaying the dialog, just like you are telling Safari to activate, for example
tellcurrent applicationtoactivate-- tell me to activate
That works. Thanks.
It turns out the root of my problem is using osascript to run scripts, which is the usual way I do that, not from Terminal but from a menu I've set up.
For example, using
osascript ~/Desktop/Test.scpt >/dev/null 2>&1
to run this script file,
tell application "Safari" to activate
delay 1
tell me to activate
delay 1
display dialog "testing…" buttons {"OK"} default button "OK" giving up after150
does not display the dialog.
Same result using osascript to run this script,
tell application "Safari"
activate
my displayMe()
end tell
on displayMe()
display dialog "testing…" buttons {"OK"} default button "OK" giving up after 150
end displayMe
but using osascript to run this script does display the dialog (without the timeout issues).
tell application "Finder"
activate
with timeout of 301 seconds-- must be longer than the "giving up" delay
display dialog "testing…" buttons {"OK"} default button "OK" giving up after 300
end timeout
end tell
Sorry for taking this thread off-track. I hope some of this has helped the OP.
Ah - this is one of those situations where it helps to explain exactly what you are doing. You can't use osascript for any user interaction, so the usual work-around (other than to run scripts the regular way) is to tell some other application to do it, for example System Events (since it is a faceless background application).
red_menace wrote:
Ah - this is one of those situations where it helps to explain exactly what you are doing. You can't use osascript for any user interaction, so the usual work-around (other than to run scripts the regular way) is to tell some other application to do it, for example System Events (since it is a faceless background application).
Yup, I have used System Events for that sort of purpose. Thanks again.
I've learned (and maybe re-learned) a few things from this discussion, including an osascript-compatible kludge for timeout.
Sorry long delay to get back to my question that I asked,
Still having issues, original I used the timeout action, and that keeps the script working.... However it still times out and then when I use the
giving up after150
I've not tested it to see if it prevents an early timeout, but clicking a the dialog and my script, just stops working there and does nothing else.
--These files need to change on boot.
--:Applications:Adobe Photoshop CS6:Presets:Scripts:SAVEAS.jsx
--:Applications:Adobe Photoshop CS6:Presets:Scripts:SaveOnly.jsx
--:Volumes:StudioC:Users:StudioC:Workflow:Folder Actions:0_HeliconHotFolder.scpt
set CS6Applications to ((path to applications folder as text) & "Adobe Photoshop CS6:Presets:Scripts")
set HeliconLabeler to ((path to home folder as text) & "Workflow:Folder Actions")
set HeliconAbdul to ((path to me as text) & "Contents:Resources:Scripts:abdul:0_HeliconHotFolder.scpt")
set HeliconMatt to ((path to me as text) & "Contents:Resources:Scripts:matt:0_HeliconHotFolder.scpt")
set HeliconShah to ((path to me as text) & "Contents:Resources:Scripts:shah:0_HeliconHotFolder.scpt")
set PS6SaveAsAbdul to ((path to me as text) & "Contents:Resources:Scripts:abdul:SAVEAS.jsx")
set PS6SaveOnlyAbdul to ((path to me as text) & "Contents:Resources:Scripts:abdul:SaveOnly.jsx")
set PS6SaveAsMatt to ((path to me as text) & "Contents:Resources:Scripts:matt:SAVEAS.jsx")
set PS6SaveOnlyMatt to ((path to me as text) & "Contents:Resources:Scripts:matt:SaveOnly.jsx")
set PS6SaveAsShah to ((path to me as text) & "Contents:Resources:Scripts:shah:SAVEAS.jsx")
set PS6SaveOnlyShah to ((path to me as text) & "Contents:Resources:Scripts:shah:SaveOnly.jsx")
tell application "System Events"
if name of current user is equal to "StudioA" then ¬
set MacName to "true"
if name of current user is not equal to "StudioA" then ¬
set MacName to "false"
end tell
with timeout of (60 * 61) seconds
display dialog "Who is using the Computer?" buttons {"Abdul", "Matt", "Shah"} with icon caution
if result = {button returned:"Abdul"} then
if MacName = "true" then
tell application "Finder"
duplicatefilePS6SaveAsAbdultofolderCS6Applications with replacing
duplicatefilePS6SaveOnlyAbdultofolderCS6Applications with replacing
end tell
else if MacName = "false" then
tell application "Finder"
duplicatefileHeliconAbdultofolderHeliconLabeler with replacing
duplicatefilePS6SaveAsAbdultofolderCS6Applications with replacing
duplicatefilePS6SaveOnlyAbdultofolderCS6Applications with replacing
end tell
display alert "Turn Camera on"
delay 1
tell application id "breezesys.com.dslrremotepro" to activate
menu_click({"DSLRRemotePro", "Camera", "Set date/time and owner string..."})
delay 1
tell application "System Events"
keystroke "a" usingcommand down
delay 1.5
keystroke "Shot_By_Abdul"
delay 1.5
keystrokereturn
end tell
end if
else if result = {button returned:"Matt"} then
if MacName = "true" then
tell application "Finder"
duplicatefilePS6SaveAsMatttofolderCS6Applications with replacing
duplicatefilePS6SaveOnlyMatttofolderCS6Applications with replacing
end tell
else if MacName = "false" then
tell application "Finder"
duplicatefileHeliconMatttofolderHeliconLabeler with replacing
duplicatefilePS6SaveAsMatttofolderCS6Applications with replacing
duplicatefilePS6SaveOnlyMatttofolderCS6Applications with replacing
end tell
display alert "Turn Camera on"
delay 1
tell application id "breezesys.com.dslrremotepro" to activate
menu_click({"DSLRRemotePro", "Camera", "Set date/time and owner string..."})
delay 1
tell application "System Events"
keystroke "a" usingcommand down
delay 1.5
keystroke "Shot_By_Matt
"
delay 1.5
keystrokereturn
end tell
end if
else if result = {button returned:"Shah"} then
if MacName = "true" then
tell application "Finder"
duplicatefilePS6SaveAsShahtofolderCS6Applications with replacing
duplicatefilePS6SaveOnlyShahtofolderCS6Applications with replacing
end tell
else if MacName = "false" then
tell application "Finder"
duplicatefileHeliconShahtofolderHeliconLabeler with replacing
duplicatefilePS6SaveAsShahtofolderCS6Applications with replacing
duplicatefilePS6SaveOnlyShahtofolderCS6Applications with replacing
end tell
display alert "Turn Camera on"
delay 1
tell application id "breezesys.com.dslrremotepro" to activate
menu_click({"DSLRRemotePro", "Camera", "Set date/time and owner string..."})
delay 1
tell application "System Events"
keystroke "a" usingcommand down
delay 1.5
keystroke "Shot_By_Shah"
delay 1.5
keystrokereturn
end tell
end if
end if
end timeout
--handlers
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar itemtopMenu)'s (menutopMenu)))
end menu_click
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
clickparentObject's menu itemf
else
my menu_click_recurse(r, (parentObject's (menu itemf)'s (menuf)))
end if
end tell
end menu_click_recurse
Can you post your script, that would help.
What I have as part of one my scripts (applescript) is the following:
with timeout of 600 seconds
-- do stuff here
end timeout
Or as well you can use the following:
display dialog "dd1" giving up after 300
That will then make it give up after 300 seconds.
Phil
You nailed it on the head. I was wondering why the giving up after 300 was not working. Thanks man.
You just need to tell your application to activate before displaying the dialog, just like you are telling Safari to activate, for example
tellcurrent applicationtoactivate-- tell me to activate
Don't put the 'with timeout' block around the whole script. it should only contain the thing you want the timeout to apply to (i.e. the display dialog command).
Display dialog, await user input how to get no timeout?