10 Replies Latest reply: Jul 17, 2014 6:53 PM by Frank Caggiano
Matteo_999 Level 1 (0 points)

Hello,

 

In my script I want to show a hidden progress bar when a button is clicked. I used the function

 

theProgress's setHidden_(false)

 

But when I press the button it gives an error "Unrecognized function setHidden_".

Is there a way to fix it?

  • Frank Caggiano Level 7 (25,722 points)

    As written that should compile and work. Without seeing the rest of your code no way to say why you are getting the error

     

    This works in code I have with progressIndicator as the outlet for the progress bar in the UI.

        on hideBut_(sender)

            progressIndicator's setHidden_(true)

        end

     

    Are you able to access the progress bar for other functions? Updating it for example.

  • Matteo_999 Level 1 (0 points)

    I tried to do that in another script, and it is:

     

    script AppDelegate

      property parent : class "NSObject"

        property progressBar : missing value

     

      -- IBOutlets

      property window : missing value

     

      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_

      

        on buttonClicked_(sender)

            progressBar's setHidden_(true)

        end buttonClicked_

     

    end script

     

    It still gives the error:


    2014-07-17 17:17:05.674 Prova[458:303] *** -[AppDelegate buttonClocked:]: Unrecognized function setHidden_. (error -10000)
    

     

    Now I'm wondering if should I import any class, such as NSView...

  • Frank Caggiano Level 7 (25,722 points)

    That should work no need to import anything, as long as the property progressBar is connected to the progress bar UI element in your xib file.

     

    So is that  the case?  One of thre drawbacks of Applescript Objective-C is you loose the visual indicator whan a conection is made between a property and it's element.

  • Matteo_999 Level 1 (0 points)

    I linked the property to the progress bar in the sections "Value" (and here i checked the option "Hide if needed") and "Hidden"

  • Frank Caggiano Level 7 (25,722 points)

    Rght click on thre UI element in Interface Builder

     

    Screen Shot 2014-07-17 at 11.29.54 .png

     

    Make sure the Referencing Outlet is connected to the correct property in your code.

     

    You can also look in the Connctions Inspector

     

    Screen Shot 2014-07-17 at 11.34.30 .png

  • Matteo_999 Level 1 (0 points)

    Even that is connected...

  • Frank Caggiano Level 7 (25,722 points)

    Could you post a screen shot of the Connections Inspector for this. Not that I don;t beleive you but perhaps I'll see somehting that you are missing.

     

    Just noticed in the error message

     

    2014-07-17 17:17:05.674 Prova[458:303] *** -[AppDelegate buttonClocked:]

    it is referring to buttonClocked:, the method where you have setHidden_ is buttonClicked. What is buttonClocked:

     

    BTW what version of Xcode are you runing?

     

    One last thing whrre are you getting that error message from?

  • Frank Caggiano Level 7 (25,722 points)

    Ok well this workd for me. It has to be in your connections

     

    --

    --  TMAppDelegate.applescript

    --  testMAt

    --

    --  Created by Frank Caggiano on 7/17/14.

    --  Copyright (c) 2014 Frank Caggiano. All rights reserved.

    --

     

    script TMAppDelegate

      property parent : class "NSObject"

     

      -- IBOutlets

      property window : missing value

        property progressBar : missing value

     

     

      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_

     

       

        on buttonClicked_(sender)

            progressBar's setHidden_(false)

        end buttonClicked_

     

     

           

    end script

     

     

    Screen Shot 2014-07-17 at 12.05.02 .png

  • Matteo_999 Level 1 (0 points)

    Thousand thanks, I checked all steps and noticed that I haven't connected the Referencing Outlet to the correct property...

    But so, don't I have to set the bindings such as "Value" or "Hidden"?

     

     

    Schermata 2014-07-17 alle 20.32.29.png

  • Frank Caggiano Level 7 (25,722 points)

    Glad you got it working.

    don't I have to set the bindings such as "Value" or "Hidden"?

    No all you need to do is connect the UI element to the  property (for output to)  or method (for input from) in your code.

     

    When you drag a UI element out and place it in the window for your app you are creating an instance of the UI Class. That is if you drag out a ProgressIndicator you create an instance of it that you can then send messages to or receive messages from. 

     

    So if oyu want to make the ProgressIndicator visible or invisible you send it the message setHidden: with the correct value (true or false). If you want to set the ProgressIndicatior you send it the message incrementBy:

     

    So if  I have a property in my code

    property progressIndicator :  missing value

     

    and I connect it to the ProgressIndicator UI element I can then do things like

    progressIndicator's setIndeterminate_(false)

    progressIndicator's setDoubleValue_(0)

    progressIndicator's setMaxValue_(60)

    To see the  messages a class implements you need to look at the classes documentation. Xcode is great for this as you can select an element in the Interface Builder and then select the Quick Help Inspector to get help and links for that particular element.

     

    So if you select the ProgressIndicator you will see

     

    Screen Shot 2014-07-17 at 21.28.11 .png

    along with links to the full class description as well as links to programming guides and sample code.

     

    Now there is a way to bind individual parts of the code, such as value and hidden. These are show in the Bindings Inspector but these are for an somewhat advanced usage, that is you can do all you need to do for now with just connection between the property and the element. What bindings enable you to do is to have a more direct and automated way for one element to affect another or for it to affect a piece of code.

     

    Let's say you have a slider that you use to input a number into your code. Also say you have a text view you use to both display the value of the slider and to also allow users to directly input a number. So when the slider moves you want the text view to update and if a user enters a number in the text view you want to set the slider to that value.

     

    Without bindings you can do this by having the slider call your code, you retrieving the value and then you display that value in the text view. Conversely if a user enters a number in the text view you can retrieve that and then set the value of the slider. This works fine and is sufficient for many programs.

     

    However with bindings it is possible for the slider to directly set the value in the text view and to have the number entered in the text view directly set the slider. One thing to keep in mind for bindings to work you need to be familiar with Key-Value Coding Programming Guide: Introduction. I

     

    This might have been more information then you were looking for or need, if so you can safely ignore it. As I said you can do what you need to do here without bindings.

     

    regards