Created
January 14, 2016 04:52
-
-
Save JMichaelTX/1e0ba4b19e28dd10732c to your computer and use it in GitHub Desktop.
DEMO & Functions for Real Progress Bar using ASObjC in AppleScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
============================================================================== | |
PURPOSE: Show how to display real Progress Bar using ASObjC Runner app | |
• Redesigned to use FUNCTIONS | |
VER: 1.1.2 DATE: Mon, May 18, 2015 | |
AUTHOR: JMichaelTX | |
Please post comment any bugs/issues/questions or suggestions for improvement | |
• All of the credit for this functionality goes to Shane Stanley, | |
who wrote the ASObjC Runner app, and many other incredible ASObjC apps | |
and libraries | |
• My only real contribution is in putting this in functions | |
REF: http://www.macosxautomation.com/applescript/apps/runner_vanilla.html | |
REQUIRES: | |
1. Mac OS X Mavericks, or later | |
2. ASObjC Runner app | |
2. ProgressBar Functions (included below) | |
1. initProgressBar(psTitle, psMsg, piMax, piCurrent) | |
2. updateProgressBar(piCurrent, piMax) | |
3. closeProgressBar() | |
The ASObjC Runner app may be downloaded from: | |
http://www.macosxautomation.com/applescript/apps/ASObjC_Runner.zip | |
Previously, there was no good way to show a standard progress bar from AppleScript. Yosemite adds a Progress Bar to AppleScript, but for Mavericks there was no good solution until ASObjC Runner. | |
This script provides a demo of the ASObjC Runner Progress Bar. I adapted the demo code from MacOSXAutomation.com to use Functions. | |
The progress window property is used to set the properties of the progress window you can display. You can set the window's name, whether it includes a button and its title, the message and detail, as well as various properties related to the progress bar. As of version 1.9.2, you can optionally have it display a second progress bar. Typically you set these properties before showing the progress window, and update them as your task proceeds. | |
There are three commands related to the progress window: reset progress will reset all the relevant properties to their default values, show progress will display the window, and hide progress will close the window. Typically you issue the reset command, set the various progress window properties to suit, show the window, update it as your script progresses, then hide it. Here is a basic example. | |
As of version 1.9.2, you can show two progress bars. | |
============================================================================== | |
*) | |
set sPBStatus to "TBD" -- Will be set to "Cancel" if User Cancels. Otherwise set to "OK" | |
--- VARIABLES TO BE SET IN YOUR SCRIPT --- | |
set sPBTitle to "ASObjC Runner Progress Bar" -- Window Title | |
set sPBMsg to "DEMO Progress Bar by ASObjC Runner" -- Msg ABOVE progress bar | |
--- FOR DEMO ONLY --- | |
set iStart to 1 | |
set iEnd to 100 | |
--------------------------------------------- | |
-- *** INITIALIZE PROGRESS BAR *** | |
my initProgressBar(sPBTitle, sPBMsg, iEnd, 0) | |
--- REPLACE with your own REPEAT LOOP --- | |
repeat with iCurrent from iStart to iEnd | |
-- *** UPDATE PROGRESS BAR JUST BEFORE YOUR PROCESSING *** | |
set sPBStatus to my updateProgressBar(iCurrent, iEnd) | |
-- HANDLE CANCEL BY USER -- | |
if (sPBStatus = "Cancel") then | |
exit repeat | |
end if | |
--- INSERT YOUR PROCESSING HERE -- | |
delay 0.1 -- for demo only, not needed in production use | |
end repeat | |
-- *** CLOSE PROGRESS BAR *** | |
my closeProgressBar() | |
--- HANDLE ANY CLEANUP IF USER CANCELED --- | |
if (sPBStatus = "Cancel") then | |
display notification ("User CANCELED process") with title sPBTitle | |
-- YOUR CODE HERE -- | |
else | |
display notification ("Process SUCCESSFULLY Completed") with title sPBTitle | |
end if -- User Canceled | |
--——————— END OF MAIN SCRIPT —————————————————————————————— | |
--———————————————————————————————— | |
-- SUBPROGRAMS | |
--———————————————————————————————— | |
--———————————————————————————————— | |
on initProgressBar(psTitle, psMsg, piMax, piCurrent) | |
(* | |
PURPOSE: Initialize the ASObjC Runner Progress Bar | |
VER: 1.1 DATE: Mon, May 18, 2015 | |
AUTHOR: JMichael (on Discussion.Evernote.com site) | |
REF: http://www.macosxautomation.com/applescript/apps/runner_vanilla.html | |
*) | |
-- NOTE: The "name" and "message" properties need to be set only here. | |
-- They will continue to show when the UPDATE is called | |
-- without being included in the properties there. | |
tell application "ASObjC Runner" | |
-- set up dialog and show it | |
reset progress | |
set properties of progress window to ¬ | |
{button title:"Cancel", button visible:true, name:psTitle, message:psMsg, detail:"", indeterminate:false, max value:piMax, current value:piCurrent} | |
activate | |
show progress | |
end tell | |
delay 0.5 | |
end initProgressBar | |
--——————————————————————————————— | |
--———————————————————————————————— | |
on updateProgressBar(piCurrent, piMax) | |
(* | |
PURPOSE: UPDATE the ASObjC Runner Progress Bar | |
VER: 1.1.1 DATE: Mon, May 18, 2015 | |
AUTHOR: JMichael (on Discussion.Evernote.com site) | |
REF: http://www.macosxautomation.com/applescript/apps/runner_vanilla.html | |
*) | |
tell application "ASObjC Runner" | |
-- By NOT activating the app during the update call, allows user to work in other apps | |
--activate | |
set properties of progress window to ¬ | |
{detail:"This is number " & piCurrent & " of " & piMax, current value:piCurrent} | |
if button was pressed of progress window then | |
--exit repeat | |
return "Cancel" | |
end if | |
end tell | |
return "OK" | |
end updateProgressBar | |
--———————————————————————————————— | |
--———————————————————————————————— | |
on closeProgressBar() | |
(* | |
PURPOSE: HIDE the ASObjC Runner Progress Bar | |
VER: 1.1 .2 DATE: Mon, May 18, 2015 | |
AUTHOR: JMichael (on Discussion.Evernote.com site) | |
REF: http://www.macosxautomation.com/applescript/apps/runner_vanilla.html | |
*) | |
tell application "ASObjC Runner" to hide progress | |
end closeProgressBar | |
--——————————————————————————————— |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the same ObjC Progress Bar in JavaScript for Automation (JXA), see:
How to Display Progress Bar Using ASObjC Runner JXA.js