Wednesday, December 12, 2018

#1 2018-12-07 01:43:48 pm

Binski
Member
Registered: 2010-01-08
Posts: 5

Add Indeterminate Circular Progress Indicator to Xcode 10 ASOBJ-C Proj

I have a rather long AppleScript that I've converted to a AppleScript Obj-C app using Xcode 10.  The only interface object is a push button that starts the script.  It runs fine, but I'd like to add a Indeterminate Circular Progress Indicator to show that the script is processing -- so users do not click the button any additional times until the script has completed with it's current task.  Ideally, it might be helpful if I disabled the push button while the Indeterminate Circular Progress Indicator is actively spinning.  I'm new to Xcode, so my knowledge of Xcode is very limited. Binding the "Start" button to the delegate is the only thing I seem to get working. What additional steps would be needed to add a Determinate Bar Progress Indicator in Xcode?

I noted there are similar and outdated post. I've reviewed many of them, but still need guidance.

Example:

    on startScript_(sender)

    -- Additional task code would go here.
       
    end startScript_

Mac OS 10.13.6
AppleScript Version 2.7
Xcode Version 10.1 (10B61)

Offline

 

#2 2018-12-09 05:08:17 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5485

Re: Add Indeterminate Circular Progress Indicator to Xcode 10 ASOBJ-C Proj

You may not realise it, but what you're asking for is effectively how to write an Xcode-based AppleScriptObjC app, and that's not something easily answered in a single reply. To make it more complicated, there's more than one way to do what you want.

here's one approach. To start, add a progress indicator to your window, and make a property that is an outlet to it -- one that has an initial value of missing value, and that you link by control-clicking on the progress indicator and choosing the property as a referencing outlet.

Your code should look something like this:

Applescript:


property progIndicator : missing value

on startScript:sender
   sender's setEnabled:false
   progIndicator's startAnimation:me
   my performSelector:"continueScript:" withObject:me afterDelay:0.1
end startScript:

on continueScript:sender
   -- do your stuff here
   sender's setEnabled:true
   progIndicator's stopAnimation:me
end continueScript:

That will get you started, although you may still see the spinning beach ball if your script takes a long time. You can find the solution to that, which is a bit more complicated, by searching here.

Good luck.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2018-12-10 12:39:48 am

Binski
Member
Registered: 2010-01-08
Posts: 5

Re: Add Indeterminate Circular Progress Indicator to Xcode 10 ASOBJ-C Proj

Thank you Shane, I really appreciate your reply.

I tried your suggestion and didn't have any luck.  I am not able to link MainMenu.xib’s progress indicator icon to the progIndicator property.  I’ve included a couple screen shots below.

AppDelegate.applescript:
[code]use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

script AppDelegate
    property parent : class "NSObject"
   
    -- IBOutlets
    property theWindow : missing value
    property progIndicator : missing value
   
    on startScript:sender
        sender's setEnabled:false
        progIndicator's startAnimation:me
        my performSelector:"continueScript:" withObject:me afterDelay:0.1
    end startScript:
   
    on continueScript:sender

         -- do your stuff here -- START
         -- EXAMPLE CODE:
         set My_List to {"1", "2", "3"} as list
         repeat with i in My_List
             display dialog i giving up after 1
         end repeat
         -- do your stuff here -- END

        sender's setEnabled:true
        progIndicator's stopAnimation:me
    end continueScript:
   
    on applicationWillFinishLaunching_(aNotification)
        -- Insert code here to initialize your application before any files are opened
    end applicationWillFinishLaunching_
   
    on applicationShouldTerminate_(sender)
        -- Insert code here to do any housekeeping before your application quits
        return current application's NSTerminateNow
    end applicationShouldTerminate_

end script[/code]

Also, I have 2 questions regarding your initial reply.

1.
Your syntax is a bit different than what I originally used.  Are they equivalent?  I tried both ways.

My Code: on startScript_(sender)
Your Code: on startScript:sender

2.
You said:
“…which is a bit more complicated, by searching here”. By “here”,  did you mean in the AppleScriptObjC and Xcode forum?  It almost sounded like you meant to include a URL link.

Button Linking
Button Linking

Progress Indicator
Progress Indicator

Error Message / Code
Error Message

Offline

 

#4 2018-12-10 12:50:24 am

Binski
Member
Registered: 2010-01-08
Posts: 5

Re: Add Indeterminate Circular Progress Indicator to Xcode 10 ASOBJ-C Proj

Sorry about the code flub.

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

script AppDelegate
   property parent : class "NSObject"
   
   -- IBOutlets
   property theWindow : missing value
   property progIndicator : missing value
   
   on startScript:sender
       sender's setEnabled:false
       progIndicator's startAnimation:me
       my performSelector:"continueScript:" withObject:me afterDelay:0.1
   end startScript:
   
   on continueScript:sender
       
       -- do your stuff here -- START
       -- EXAMPLE CODE:
       set My_List to {"1", "2", "3"} as list
       repeat with i in My_List
           display dialog i giving up after 1
       end repeat
       -- do your stuff here -- END
       
       sender's setEnabled:true
       progIndicator's stopAnimation:me
   end continueScript:
   
   on applicationWillFinishLaunching:aNotification
       -- Insert code here to initialize your application before any files are opened
   end applicationWillFinishLaunching:
   
   on applicationShouldTerminate:sender
       -- Insert code here to do any housekeeping before your application quits
       return current application's NSTerminateNow
   end applicationShouldTerminate:
   
end script

Offline

 

#5 2018-12-10 05:00:54 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5485

Re: Add Indeterminate Circular Progress Indicator to Xcode 10 ASOBJ-C Proj

Binski wrote:

I tried your suggestion and didn't have any luck.  I am not able to link MainMenu.xib’s progress indicator icon to the progIndicator property.  I’ve included a couple screen shots below.



They don't appear. Hold down the control key and click and drag from the indicator to File's Owner at the top-left; choose the property name from the list that appears.

Your syntax is a bit different than what I originally used.  Are they equivalent?  I tried both ways.



They the same -- the colon-delimited version was introduced in macOS 10.10. Open and compile in a script editor, and you will see.

By “here”,  did you mean in the AppleScriptObjC and Xcode forum?



Yes.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#6 2018-12-10 11:35:43 am

Binski
Member
Registered: 2010-01-08
Posts: 5

Re: Add Indeterminate Circular Progress Indicator to Xcode 10 ASOBJ-C Proj

Shane, I can't express how much I appreciate your help!  I finally was able to get it to work. As you noted, the progress indicator does continue to spin after the script completes, but I'll search the forum for solutions as you noted.  I'll post the complete solution when I have it.

I did know that I needed to old down the control key and drag to link the interface. I had been clicking and dragging from the indicator, just as I had done for the button object. What actually worked, was clicking and dragging from the App Delegate to the Progress Indicator and then selecting the outlet. It is directionally specific!

It is insane that doing such simple things have been made so difficult. I love to hate AppleScript for the same reason. Apple has spent resources engineering all of this technology into their products, only to let it languish in the dark. I spent countless hours over a week searching the web to do this one simple thing!

Offline

 

#7 2018-12-10 05:41:23 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5485

Re: Add Indeterminate Circular Progress Indicator to Xcode 10 ASOBJ-C Proj

Binski wrote:

It is directionally specific



It can be done in either direction -- it's just a bit different each way.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#8 Today 12:12:03 am

Binski
Member
Registered: 2010-01-08
Posts: 5

Re: Add Indeterminate Circular Progress Indicator to Xcode 10 ASOBJ-C Proj

The script almost does what I want, except when the app launches, it shows the progress indicator on the initial app window.

I've attached a screen video that shows the app run through two cycles.  The 1st starts from the initial screen as it appears upon launch.  The second cycle shows how I'd like the app to work -- no progress indicator until the button is clicked.

I tried many iterations with various code. Examples include: displayedWhenStopped, theWindow's update_(), various progIndicator's setHidden: and various handlers in an attempt to hide the progress indicator before the initial app screen displays.

In my initial post, I suggested disabling the button once it was pressed, but that isn't needed since you cannot click the button while the progress indicator animates.

I've had no luck, and don't have a clue how to proceed.  Any suggestions?


Screen Video of App

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

script AppDelegate
   property parent : class "NSObject"
   
   -- IBOutlets
   property theWindow : missing value
property progIndicator : missing value
property setSpinnerHidden : missing value

on startScript:sender

progIndicator's setHidden:1

my performSelector:"continueScript:" withObject:me afterDelay:0.3

end startScript:


on continueScript:sender

-- SHOW progIndicator
progIndicator's setHidden:0
progIndicator's startAnimation:me

-- do your stuff here -- START
-- EXAMPLE CODE:
set My_List to {"1", "2", "3"} as list
repeat with i in My_List
display dialog i giving up after 1
end repeat
-- do your stuff here -- END

-- HIDE progIndicator
progIndicator's setHidden:1
progIndicator's stopAnimation:me

end continueScript:


   on applicationWillFinishLaunching_(aNotification)
       -- Insert code here to initialize your application before any files are opened
   end applicationWillFinishLaunching_


   on applicationShouldTerminate_(sender)
       -- Insert code here to do any housekeeping before your application quits
       return current application's NSTerminateNow
   end applicationShouldTerminate_

end script

Offline

 

#9 Today 12:43:02 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5485

Re: Add Indeterminate Circular Progress Indicator to Xcode 10 ASOBJ-C Proj

None of your links are appearing.

Look at this thread: https://macscripter.net/viewtopic.php?id=46038


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)