Jump to content

How to add a "confirm" option to a workflow?


Recommended Posts

Here you go... look at these to figure it out from here.

display dialog "this is the text"
display dialog "this is the text" with title "this is a title"
display dialog "this is the text" buttons {"cancel", "okay"}
display dialog "this is the text" buttons {"cancel", "okay"} default button 2
display dialog "this is the text" with icon Note
display dialog "this is the text" with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:SideBarDownloadsFolder.icns"
display dialog "this is the text" buttons {"Cancel","Confirm"} default button 2 with title "this is a title" with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:SideBarDownloadsFolder.icns"

Bash:

osascript -e 'display dialog "this is the text" buttons {"Cancel","Confirm"} default button 2 with title "this is a title" with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:SideBarDownloadsFolder.icns"'

Capturing:

output = $(osascript -e 'display dialog "this is the text" buttons {"Cancel","Confirm"} default button 2 with title "this is a title" with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:SideBarDownloadsFolder.icns"')
answer=${output#button returned:}

If you want to use any other language, then you want to run it through the system command anyway. Just make sure you escape everything correctly.

 

Untested for PHP:

answer = exec('output = $(osascript -e "display dialog \"this is the text\" buttons {\"Cancel\",\"Confirm\"} default button 2 with title \"this is a title\" with icon file \"System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:SideBarDownloadsFolder.icns\"") && echo ${output#button returned:}');
Link to comment
  • 2 weeks later...

Oh wow ! Thanks you.

 

Another way to do this would be to use External Triggers and a Script Filter. Do whatever you need then use an Output->Run Script, to call an External Trigger. The External Trigger is connected to a Script Filter with 2 options, a Yes and a No, or a Description (with valid=false) and a Yes and No. Then just proceed based on what they select. Personally, I would prefer this over the AppleScript dialogs

Link to comment

It's a more Alfred-y solution, but it does complicate the workflow logic much more than the AppleScript option.

 

This is one of many complex logic problems that could be solved if Alfred's AppleScript API allowed workflows to call Alfred and receive the output.

 

Currently, Alfred's HTTP-like stateless nature makes doing this kind of thing just with Alfred very complex: it's up to workflow devs to implement their own version of cookies and sessions.

Link to comment
  • 4 years later...

There is an error in bash capturing

It should remove the spaces around the equal sign.

output=$(osascript -e 'display dialog "this is the text" buttons {"Cancel","Confirm"} default button 2 with title "this is a title" with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:SideBarDownloadsFolder.icns"')
answer=${output#button returned:}

or just like this

answer=$(osascript -e 'button returned of (display dialog "this is the text" buttons {"Cancel","Confirm"} default button 1 with title "this is a title" with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:AlertStopIcon.icns")')

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...