Multi-script project?

Hi,

To prevent my script from becoming too “crowded” i’d like to split one script into many.

I’d like to have one script-file that handles the launch process, one script file that that handles every button press, one script-file to check for updates and so on. I tried to accomplish this by adding a new NSObject, the problem is that this new object isn’t connected to any applescript file.

Thank you very much!

You need to click on the blue cube, then show the Identity Inspector, and enter the class name where it says “Class”.

thanks for your quick reply!

I already tried that but got this error:

Edit: However when i click on the little arrow next to the class it does guide me to the correct script…

The class name must match the script file name and the script class name “ according to the screenshot it’s SendMessage

That’s telling you you don’t have a class called NewMessage. The class name is the bit following the word “script” at the beginning of your script file.

when i click here:

it sends me here:

so it would seem it should work…

Your parent property refers to a class that doesn’t exist. You can’t make an AS class a subclass of another AS class, so that should be NSObject or some other Cocoa class.

No luck either with ObjectWithFords nor NSObject

the error message says a class called “NewMessage”. Did you have such a class at some stage and link something in the interface to it?

No i did not, i did have sendNewMessage which xcode also seems to keep refering to although i removed it

f it’s not too complex, you might want to consider deleting most of the things in your interface and redoing them. It sounds like something might have been corrupted.

Rebuilding the interface did work. The only received action that won’t be recognized is sendNewMessage. There must still be something wrong. stay tuned…

well somehow IB still think there is a sendNewMessage. atm i got this:

It’s getting stranger every minute…

when i do this it only recognizes NEWMSGBTN (Just copied that from the other script to test)


script SendMessage
property parent : class "ObjectWithFords"
    property test : missing value
    property Receiver : missing value
    property Subject : missing value
    property Content : missing value

on PrepareMessage_(sender)
    log "Grabbing textfield value's..."
    set theReceiver to Receiver's stringValue() as text
    log "Receiver: " & theReceiver
    set theSubject to Subject's stringValue() as text
    log "Subject: " & theSubject
    set theContent to Content's stringValue() as text
    log "Content: " & theContent
end PrepareMessage_
    
on NEWMSGBTN_(sender)
        log "New message button triggered"
        try
            NewMessageWindow's showOver_(MainWindow)
            on error
            log "NewMessageWindow couldn't showover"
            NewMessageWindow's orderFront_(me)
            
        end
    end NEWMSGBTN_
end script

And when i do this it only recognizes SendMessage1


script SendMessage
property parent : class "ObjectWithFords"
    property test : missing value
    property Receiver : missing value
    property Subject : missing value
    property Content : missing value

on PrepareMessage_(sender)
    log "Grabbing textfield value's..."
    set theReceiver to Receiver's stringValue() as text
    log "Receiver: " & theReceiver
    set theSubject to Subject's stringValue() as text
    log "Subject: " & theSubject
    set theContent to Content's stringValue() as text
    log "Content: " & theContent
end PrepareMessage_
    
on NEWMSGBTN_(sender)
        log "New message button triggered"
        try
            NewMessageWindow's showOver_(MainWindow)
            on error
            log "NewMessageWindow couldn't showover"
            NewMessageWindow's orderFront_(me)
            
        end
    end NEWMSGBTN_

    on PrepareMessage1_(sender)
        log "Grabbing textfield value's..."
        set theReceiver to Receiver's stringValue() as text
        log "Receiver: " & theReceiver
        set theSubject to Subject's stringValue() as text
        log "Subject: " & theSubject
        set theContent to Content's stringValue() as text
        log "Content: " & theContent
    end PrepareMessage_

end script

I’m not sure what’s happening. Control-click on the file in Navigator and choose Open with External Editor. This will open it in your script editor; compile it there and save, to make sure it compiles OK.

I’m not sure either. But somehow it is now working perfectly. What i did was make sure i ended the routine correctly and hit tab a few times. It’s working as expected now! Anyway as i’m only at the beginning of this project i’ll probably get a lot more problems (with NSScrollview, mostly). Anyway, thank you both!

This is another reason why using an external editor is a good idea – you can spot problems in compiled code, not just raw text.

Mmm what’s that editor called again?

Edit: nvm found it, script debugger 4.5

Something else, but related:

I’d like to load handlers from another script. So i tried to use this:

set ScriptLoc to ((current application's NSBundle's mainBundle()'s bundlePath()) as text) & "/Contents/Resources/FirstRun.scpt" as text
        set FirstRun to load script ScriptLoc
        FirstRun's Boom_()

However it always return me

I tried to set the ScriptLoc as alias and as string, both make it impossible for load script to find FirstRun.scpt. Seeing it says it can’t recognize the function i guess there would be something wrong with the target script. But that doesn’t seem likely to me, sinds the only thing in there atm is the empty Boom_() handler.

Any ideas?

Thanks in forward!

Try putting your script somewhere other than loose in Resources; that’s where scripts are loaded from by ASObjC at app launch time.