Jump to content
politicus

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:}');

Share this post


Link to post

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

Share this post


Link to post

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.

Share this post


Link to post

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")')

 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...