benWin
benWin

Reputation: 25

Xcode Applescript create list of results

I have been trying to work out the best way to accomplish this and every time I think I am on to something it doesn't seem to work in my situation.

If someone could point me in the right direction to an existing example or the correct google term I would be very grateful.

I am creating a Cocoa - Applescript Application in Xcode 5.

I have the basics in already, which so far prompts the user to select an audio track, the track is then played back in Quick Time and I have a button to return the current play time of the track, as it stands at the moment this returns the time to a variable of SMPTE ala.

tell application "QuickTime Player"
        set SMPTE to get current time of document 1
    end tell

My problem is what to do with the result of "SMPTE"

I would like to generate a list in a separate window with each button press updating a new row with the new returned value.

I have tried using a NSTableColumn but can't work out how to "auto fill" with each subsequent button press.

Upvotes: 0

Views: 731

Answers (1)

markhunte
markhunte

Reputation: 6932

A very simplistic way.

Add an NSArrayController to the IB Objects.

Connect it to an outlet.
Select the TableView's TableColumn and go to it Bindings Inspector.

Bind it's Value to Array Controller

And name it's model key path as 'time'

In the TableColumn's Attributes Inspector. Set it's Title to 'time'

The code would be like this:

 property ArrayController :missing value



    on addTime_(sender) --clicked to add time
        tell application "QuickTime Player"
            set SMPTE to get current time of document 1
        end tell

        ArrayController's addObject:{|time|:SMPTE}
    end addTime_

The Button would need to be connected to the Action: addTime:


To remove an item:

Simply add a new button and connect it to the ArrayController's Remove Action method. ( By dragging the button's connection to the ArrayController object in IB and selecting remove: )


To Save the data to be able to see it on relaunch:

Select the ArrayController object in IB and go to it's bindings inspector. Bind it's Control Content's content Array to the 'Shared user defaults Controller'

And name it's model key path as 'theValues'


There is a very good intro tutorial here

And NSArrayController's Docs

Upvotes: 2

Related Questions