Demo of real Progress Bar using ASObjC Runner app

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.

Please feel free to post a reply or PM me with any bugs/issues/questions.

Developed/tested running Mac OS X Mavericks (10.9.5)


(*
==============================================================================
PURPOSE:  Show how to display real Progress Bar using ASObjC Runner app
			¢ Redesigned to use FUNCTIONS

VER:	1.1		DATE:  Mon, May 18, 2015

AUTHOR:		JMichael (member of Discussion.Evernote.com forum)
			JMichaelTX (member of macscripter.net forum)
				Please PM me with any bugs/issues/questions
				
			Most of the credit goes to MacOSXAutomation.com
			
REF:  	http://www.macosxautomation.com/applescript/apps/runner_vanilla.html

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(sPBTitle, 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 hideProgressBar()

--- 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(psTitle, piCurrent, piMax)
	(*
	PURPOSE:  UPDATE 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
	*)
	
	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 hideProgressBar()
	
	(*
	PURPOSE:  HIDE 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
	*)
	
	tell application "ASObjC Runner" to hide progress
	
	
end hideProgressBar
--”””””””””””””””””””””””””””””””

Model: MBP-15R, Early 2013
Browser: Safari 7.6.1
Operating System: Mac OS X Mavericks (10.9.5)

Thank you.

As the person who wrote ASObjC Runner, I’d just like to reiterate that although it still works with Yosemite, it is discontinued.

Shane, thanks for a great piece of software! I wish I had discovered it much earlier.

There are so many great functions added by ASObjC Runner, I hate to see it discontinued.
Have these been replaced by something else in Yosemite?
Is there any harm or issues if I continue to use ASObjC Runner in Yosemite?

Thanks again.

Model: MBP-15R, Early 2013
Browser: Safari 7.1.6
Operating System: Mac OS X (10.9)

Apart from the progress bar, the rest is mostly available in BridgePlus via AppleScriptObjC. You should see a notice about it here from just the other day.

There are a couple of other apps that display progress bars, and of course AppleScript has its own in Yosemite, although with a big drawback.

At this stage I know quite a few people running it without problem. But I think it’s better to move to an alternative before there are problems.

Thanks for your reply Shane.

Could you please point me to some references about ASObjC that will help me answer these questions:

  1. When do I need to use ASObjC instead of just AppleScript?
  2. What is the purpose of ASObjC?
  3. Where does it fit in the range of programming options on the Mac?
  4. How much more difficult is it to learn and use ASObjC than AppleScript?
  5. If I want to learn how to program in ASObjC what are some good training materials?
    (I especially like video tutorials where the student can follow along)

Just so you know, I have done quit a bit of searching via Google and your web site, found lots of stuff, but nothing that seemed to really address the above question. Maybe I just missed it.

Many thanks.

JMichael

There are two branches to ASObjC. One is the use of it to build full-blown apps with interfaces in Xcode, and the other is the ability added in Mavericks, to use it directly in AppleScript scripts. i’m assuming the latter is more what you’re asking about, so …

When you want to do something you can’t do otherwise, or can’t do efficiently otherwise. A simple example: AppleScript has no way to change the case of a string, but you can do it with ASObjC. Another example: you can’t add or remove tags on files in the Finder or via System Events, but can do it directly using ASObjC.

The language nearly all applications are written in is Objective-C. ASObjC is a way of writing Objective-C using AppleScript. And Objective-C is needed to get access to the Cocoa frameworks – the stuff that makes Macs Macs. It also lets you access third-party frameworks, which is what is inside BridgePlus.

For example, suppose you want to make a folder. Instead of telling the Finder to do it, you can call the code the Finder uses. If you want to sort a list of strings using the sorting routine the Finder uses, you can do that directly.

It’s just an extension of AppleScript. AppleScript Plus, if you like.

There are two aspects to it. Once is learning the mechanics – that’s reasonably simple. The other is learning how the classes within the frameworks can be used, and that can be more complex – think of each class as being potentially another app you have to understand to script. Some are straight-forward, some are remarkably obtruse.

The only detailed ones I know of are my book. I don’t think anyone else has done much on it – if they have, I suspect you would have found it. A video is an interesting idea, but I’m not sure the market justifies the expense. I know it hasn’t really for my book.

Let me know if it’s still not clear.

Shane, that was perfect! Just what I needed.
Thank you so much for taking the time to directly answer all my questions – I never expected that.

OK, so I’m going to order your book tomorrow.