views:

175

answers:

3

Is there a way to use defined AppleScript methods in other AppleScripts which reference the original AppleScript with something similar to import (f.e. in PHP)?

I wrote a methode to set Skype status and mood-text:

on setSkypeStatus(status, mood_text)
    tell application "System Events"
        set skypeRunning to count (every process whose name is "Skype")

        if skypeRunning > 0 then --only set status if skype is running
            tell application "Skype"
                set myStatus to "SET USERSTATUS " & status
                set myMood to "SET PROFILE MOOD_TEXT " & mood_text

                send command myStatus script name "AppleScript"
                send command myMood script name "AppleScript"
                return skypeRunning
            end tell
        else
            return skypeRunning
        end if
    end tell
end setSkypeStatus

now I'm searching for something like import skype_methods.scpt. Is there such a functionality. I can't something related with Google.

+2  A: 

Script Foo.scpt

set theBar to "path:to:Bar.scpt" as alias
run script (theBar)

Script Bar.scpt

display dialog "Bar"

Result: A window that displays "Bar"

Philip Regan
+3  A: 

One way to import another script as a library is to define a property which is initialized by loading the library as a script object. You can then use the tell command to invoke the library functions.

property pSkypeLibrary : load script POSIX file "/Users/sakra/Desktop/skype_methods.scpt"

tell pSkypeLibrary
    setSkypeStatus("status", "mood")
end tell
sakra