client = bundler.wrapper('cocoadialog')
If you wish to enabled debugging, set the debug parameter to true.
client = bundler.wrapper('cocoadialog', debug=True)
This page is a simple introduction into using the CocoaDialog wrappers supplied in The Alfred Bundler.
Although they are not shown here, there are many default icons and dialog types to choose from in the CocoaDialog application. To see the full documentation of icons and dialog types supported by these wrappers please see the CocoaDialog Reference page.
Note: the use of external dialogs in Alfred workflows is a sensitive subject. In order to provide the highest quality workflow, please follow the defined standards found at the CocoaDialog Standards page.
$client = $bundler->wrapper('cocoadialog')
If you wish to enabled debugging, set the debug parameter to true.
$client = $bundler->wrapper('cocoadialog', $debug=true)
client = bundler.wrapper('cocoadialog')
If you wish to enabled debugging, set the debug parameter to true.
client = bundler.wrapper('cocoadialog', debug=True)
@client = @bundler.wrapper('cocoadialog')
If you wish to enabled debugging, set the debug parameter to true.
@client = @bundler.wrapper('cocoadialog', debug=true)
If you want to spawn awesome dialog boxes like the one to the right, you must call the type of dialog you want using acceptable parameters.
A list of all available dialogs and accepted parameters can be found at the CocoaDialog Reference page.
All dialogs are spawned in the same basic format...
output_capture = client.dialog_type(**valid_argument=**valid_value)
Following the format above, we can spawn the dialog above with the following client calls.
$my_message_box = $client->msgbox([
'title'=>'My Message Box',
'text'=>'This is the heading of my message box',
'informative_text'='Informational text goes in here',
'button1'=>'Click Me!',
'button2'=>"Don't click me...",
'icon'=>'info'
]);
my_message_box = client.msgbox(
title='My Message Box',
text='This is the heading of my message box',
informative_text='Informational text goes in here',
button1='Click Me!',
button2='Don\'t click me...',
icon='info'
)
my_message_box = @client.msgbox(
title:'My Message Box',
text:'This is the heading of my message box',
informative_text:'Informational text goes in here',
button1:'Click Me!',
button2:'Don\'t click me...',
icon:'info'
)
Progress bars are extremely useful for giving the user an idea of how long some opperation is taking.
Since the implementation of progress bars can be fairly confusing from the raw CocoaDialog application, we have simplified it down to a few methods.
Note that the Python variant of the CocoaDialog wrapper handles spawning progress bars differently from the PHP, and Ruby variants.
$my_progress_bar = new ProgressBar($client, [
'title'=>'My Progress Bar',
'percent'=>0,
'text'=>'[0 of 100] Processing stuff...',
'icon'=>'finder'
]);
my_progress_bar = client.progressbar(
title='My Progress Bar',
percent=0,
text='[0 of 100] Processing stuff...',
icon='finder'
)
my_progress_bar = Alfred::ProgressBar.new(@client,
title:'My Progress Bar',
percent:0,
text:'[0 of 100] Processing stuff...',
icon:'finder'
)
Updating the progress bar is also very easy to implement. Simply call the update method in the progress bar class.
For this example implementation I'll use a random wait time to simmulate some process where you might need to use a progress bar.
foreach(range(0, 101) as $n) {
//...< your process here >...
$my_progress_bar->update($percent=$n, $text=sprintf('[%d of 100] Processing stuff...', $n));
time_nanosleep(0, 100000000);
}
import time
for n in range(101):
#...< your process here >...
my_progress_bar.update(percent=n, text='[%d of 100] Processing stuff...' % n)
time.sleep(0.1)
(0..100).step(1) do |n|
#...< your process here >...
my_progress_bar.update(percent=n, text='[%d of 100] Processing stuff...' % n)
sleep(0.1)
end
If you want to allow your progress bar to be stopped, you will have to set your loop to check if the progress bar is still alive.
By default, the progress bar update method will return the integer 1 if the progress bar is still alive. If the user presses the stop button, the progress bar will die and the next update method will return the integer 0 instead.
To catch the output of the update method, format your loop similar to the following example.
$my_stoppable_progress_bar = new ProgressBar($client, [
'title'=>'My Progress Bar',
'percent'=>0,
'text'=>'[0 of 100] Syncing...',
'icon'=>'sync',
'stoppable'=>true
]);
foreach(range(0, 101) as $n) {
//...< your process here >...
if($my_stoppable_progress_bar->update(
$percent=$n,
$text=sprintf('[%d of 100] Syncing...', $n)
) == 0) {
// User stopped progress bar...
break;
}
time_nanosleep(0, 100000000);
}
my_stoppable_progress_bar = client.progressbar(
title='My Progress Bar',
percent=0,
text='[0 of 100] Syncing...',
icon='sync',
stoppable=True
)
import time
for n in range(101):
#...< your process here >...
if my_stoppable_progress_bar.update(
percent=n,
text='[%d of 100] Syncing...' % n
) == 0:
# User stopped progress bar...
break
time.sleep(0.1)
my_stoppable_progress_bar = Alfred::ProgressBar.new(@client,
title:'My Progress Bar',
percent:0,
text:'[0 of 100] Syncing...',
icon:'sync',
stoppable:true
)
(0..100).step(1) do |n|
#...< your process here >...
if my_stoppable_progress_bar.update(
percent=n,
text='[%d of 100] Syncing...' % n
) == 0
# User stopped progress bar...
break
end
sleep(0.1)
end