I currently have a property that sets the location of all of my “plugins”. I would like to bypass this by placing all of my plugins inside of my app. I cannot figure out how to successfully do that in the following script:
using terms from application "iChat"
property scriptLoc : ((path to desktop folder as text) & "AAIR:") -- Location of the commands
property timeCommand : load script file (scriptLoc & "time.scpt")
property externalIPCommand : load script file (scriptLoc & "external IP.scpt")
property processCommand : load script file (scriptLoc & "process.scpt")
property emailCommand : load script file (scriptLoc & "email.scpt")
property GoogleCommand : load script file (scriptLoc & "Google.scpt")
property helpCommand : load script file (scriptLoc & "help.scpt")
property iTunesCommand : load script file (scriptLoc & "iTunes.scpt")
property sayCommand : load script file (scriptLoc & "say.scpt")
property volumeCommand : load script file (scriptLoc & "volume.scpt")
property weatherCommand : load script file (scriptLoc & "weather.scpt")
property WikiCommand : load script file (scriptLoc & "Wiki.scpt")
property activateCommand : load script file (scriptLoc & "activate.scpt")
property echoCommand : load script file (scriptLoc & "echo.scpt")
property killCommand : load script file (scriptLoc & "kill.scpt")
property sendCommand : load script file (scriptLoc & "send.scpt")
property TinyURLCommand : load script file (scriptLoc & "TinyURL.scpt")
property uptimeCommand : load script file (scriptLoc & "uptime.scpt")
property creditsCommand : load script file (scriptLoc & "credits.scpt")
on load(theMessage)
set staticCommand to text 1 thru ((offset of " " in theMessage) - 1) of theMessage
set dynamicCommand to text ((offset of " " in theMessage) + 1) thru -1 of theMessage
set theResponse to ""
if theMessage is "external IP" then set theResponse to externalIPCommand's AAIR()
if staticCommand is "time" then set theResponse to timeCommand's AAIR()
if staticCommand is "process" then set theResponse to processCommand's AAIR()
if staticCommand is "uptime" then set theResponse to uptimeCommand's AAIR()
if staticCommand is "credits" then set theResponse to creditsCommand's AAIR()
if staticCommand is "email" then set theResponse to emailCommand's AAIR(dynamicCommand)
if staticCommand is "Google" then set theResponse to GoogleCommand's AAIR(dynamicCommand)
if staticCommand is "help" then set theResponse to helpCommand's AAIR(dynamicCommand)
if staticCommand is "iTunes" then set theResponse to iTunesCommand's AAIR(dynamicCommand)
if staticCommand is "say" then set theResponse to sayCommand's AAIR(dynamicCommand)
if staticCommand is "volume" then set theResponse to volumeCommand's AAIR(dynamicCommand)
if staticCommand is "weather" then set theResponse to weatherCommand's AAIR(dynamicCommand)
if staticCommand is "Wiki" then set theResponse to WikiCommand's AAIR(dynamicCommand)
if staticCommand is "activate" then set theResponse to activateCommand's AAIR(dynamicCommand)
if staticCommand is "echo" then set theResponse to echoCommand's AAIR(dynamicCommand)
if staticCommand is "kill" then set theResponse to killCommand's AAIR(dynamicCommand)
if staticCommand is "send" then set theResponse to sendCommands's AAIR(dynamicCommand)
if staticCommand is "TinyURL" then set theResponse to TinyURLCommand's AAIR(dynamicCommand)
if theResponse is "" then set theResponse to "Invalid Command!"
return theResponse
end load
display dialog "Command to test: " default answer ""
set theMessage to the text returned of the result
set theResponse to load(theMessage)
display dialog theResponse
on message received theMessage from theBudy for theChat
set theResponse to load(theMessage)
send theResponse to theChat
end message received
end using terms from
Whenever I try to set the scriptLoc to ((path to me) & “Contents:Resources:Plugins”) Script editor will error out saying that that location does not exist inside of ScriptEditor.app. Obviously it’s not there, it’s in the app I am trying to create.
Um, did you actually save the script as bundle or application, and place those libraries in its Resources folder?
I don’t think it’s necessary to use a Plugins folder;
with ‘path to resource’ you can get any file in the Resources folder.
And yes, with ‘path to me’ the script won’t find its resources when run from Editor.
I just wrote a script bundle to create a few folders, and give them a custom icon.
To get the icons it uses this command:
is no valid HFS path, it’s a list containing an alias and a literal string {alias “Path to me”, “Contents.”}
To get a path use the as text parameter
((path to me as text) & “Contents:Resources:Plugins:”)
Create your application bundle, then move the scripts to the appropriate location.
Two notes:
¢ never use a relative path (path to. ) in a property. After the script is compiled, it will work only on the machine where it has been created.
¢ The multiple if - then lines are quite expensive, because all of them are executed every time. An if - else if chain is much better
property scriptLoc : ((path to me as text) & "Content:Reources:Plugins:") -- Location of the commands
But I am getting the same error when I try to save the application.
Thanks!
Also I did the else if statements as you suggested.
using terms from application "iChat"
property scriptLoc : ((path to me as text) & "Content:Reources:Plugins:") -- Location of the commands
property timeCommand : load script file (scriptLoc & "time.scpt")
property externalIPCommand : load script file (scriptLoc & "external IP.scpt")
property processCommand : load script file (scriptLoc & "process.scpt")
property emailCommand : load script file (scriptLoc & "email.scpt")
property GoogleCommand : load script file (scriptLoc & "Google.scpt")
property helpCommand : load script file (scriptLoc & "help.scpt")
property iTunesCommand : load script file (scriptLoc & "iTunes.scpt")
property sayCommand : load script file (scriptLoc & "say.scpt")
property volumeCommand : load script file (scriptLoc & "volume.scpt")
property weatherCommand : load script file (scriptLoc & "weather.scpt")
property WikiCommand : load script file (scriptLoc & "Wiki.scpt")
property activateCommand : load script file (scriptLoc & "activate.scpt")
property echoCommand : load script file (scriptLoc & "echo.scpt")
property killCommand : load script file (scriptLoc & "kill.scpt")
property sendCommand : load script file (scriptLoc & "send.scpt")
property TinyURLCommand : load script file (scriptLoc & "TinyURL.scpt")
property uptimeCommand : load script file (scriptLoc & "uptime.scpt")
property creditsCommand : load script file (scriptLoc & "credits.scpt")
on load(theMessage)
set staticCommand to text 1 thru ((offset of " " in theMessage) - 1) of theMessage
set dynamicCommand to text ((offset of " " in theMessage) + 1) thru -1 of theMessage
set theResponse to ""
if theMessage is "external IP" then
set theResponse to externalIPCommand's AAIR()
else if staticCommand is "time" then
set theResponse to timeCommand's AAIR()
else if staticCommand is "process" then
set theResponse to processCommand's AAIR()
else if staticCommand is "uptime" then
set theResponse to uptimeCommand's AAIR()
else if staticCommand is "credits" then
set theResponse to creditsCommand's AAIR()
else if staticCommand is "email" then
set theResponse to emailCommand's AAIR(dynamicCommand)
else if staticCommand is "Google" then
set theResponse to GoogleCommand's AAIR(dynamicCommand)
else if staticCommand is "help" then
set theResponse to helpCommand's AAIR(dynamicCommand)
else if staticCommand is "iTunes" then
set theResponse to iTunesCommand's AAIR(dynamicCommand)
else if staticCommand is "say" then
set theResponse to sayCommand's AAIR(dynamicCommand)
else if staticCommand is "volume" then
set theResponse to volumeCommand's AAIR(dynamicCommand)
else if staticCommand is "weather" then
set theResponse to weatherCommand's AAIR(dynamicCommand)
else if staticCommand is "Wiki" then
set theResponse to WikiCommand's AAIR(dynamicCommand)
else if staticCommand is "activate" then
set theResponse to activateCommand's AAIR(dynamicCommand)
else if staticCommand is "echo" then
set theResponse to echoCommand's AAIR(dynamicCommand)
else if staticCommand is "kill" then
set theResponse to killCommand's AAIR(dynamicCommand)
else if staticCommand is "send" then
set theResponse to sendCommands's AAIR(dynamicCommand)
else if staticCommand is "TinyURL" then
set theResponse to TinyURLCommand's AAIR(dynamicCommand)
else if theResponse is "" then
set theResponse to "Invalid Command!"
end if
return theResponse
end load
display dialog "Command to test: " default answer ""
set theMessage to the text returned of the result
set theResponse to load(theMessage)
display dialog theResponse
on message received theMessage from theBudy for theChat
set theResponse to load(theMessage)
send theResponse to theChat
end message received
end using terms from
I thought that the path to me bug has been fixed in Snow Leopard.
While running the script in Script Editor path to me is the path to the ScriptRunner (Script Editor).
It works correctly while running the script stand alone.
But maybe there is a preference setting to change the behavior.
The problem does not occur in Script Debugger
PS: there is still relative paths in the property lines!
Saved as application bundle the script won’t be portable at all.
And put the using terms from block only around the iChat event handler
Aaon, your top property has a path which starts at the HD.
When the script is compiled the property is fixed to that value.
When you run the script on another Mac, it will only work when the startup disk has the exact same name.
So, in such a property use a partial path, and add the boot disk name on the fly:
property desktopPic_path : "Library:Desktop Pictures:Solid Colors:Solid Aqua Graphite.png"
set thePath to ((POSIX file "/" as text) & desktopPic_path) as alias
To phrase it differently: use only constants in properties.
Stefan, so your saying ((path to desktop)) is messing up the relative paths? I really don’t get what your saying with that.
I created a test script and put the scriptLoc inside of the load handler. This works for some reason. I though if it was a property i didn’t have to be inside the handler, it could be at the top of the script?
Script that worked:
on load(theMessage)
set myLoc to ((path to me as text) & "Contents:Resources:Plugins:")
set timeCommand to load script file (myLoc & "time.scpt")
if theMessage is "time" then set theResponse to timeCommand's AAIR()
end load
display dialog "Command to test: " default answer ""
set theMessage to the text returned of the result
set theResponse to load(theMessage)
display dialog theResponse
I want the app to be movable. When iChat imports it it move it to it’s script folder. Errrg… It’s been a long day. I’m going to step away for a few. Hopefully when I come back I can wrap my head around what’s being said here. For some reason I am just not getting it…
The best programming habit is to implement the run handler to define all paths and set the properties
for example, if your startup disk is named Macintosh HD and the short user name is “myName” path to desktop sets the property at compile time to alias “Macintosh HD:Users:myName:Desktop”.
When the script runs on a Mac with a different startup volume name or short user name the script will fail
on run
property scriptLoc : ((path to me as text) & "Content:Resources:Scripts")
set scriptLoc to ((POSIX file "/" as text) & desktopPic_path) as alias
property timeCommand : load script file (scriptLoc & "time.scpt")
end run
on load(theMessage)
if theMessage is "time" then
set theResponse to timeCommand's AAIR()
end load
display dialog "Command to test: " default answer ""
set theMessage to the text returned of the result
set theResponse to load(theMessage)
display dialog theResponse
should work? I tried to add what alastor933 said. The reason I want to do the path to me is because I know people move stuff in their applications folder. When I set up the alert in iChat it creates a copy of the script in it own script folder. If someone moved iChat to Applications/IM/iChat there is no way I would be able to have the script find its plugins.
property scriptLoc : missing value
property timeCommand : missing value
on run
set scriptLoc to ((path to me as text) & "Contents:Resources:Scripts:") -- don't forget the trailing colon
set timeCommand to load script file (scriptLoc & "time.scpt")
end run
Thansk stefan. I’m going to leave this here for now for today. I think you have the fix for me… If I have any more issues I will be back. But for now… we can call this quits
edit+
Alright Stefan, you are the man! Thanks everyone for your help.
Trying out some new meds, and they are kicking my ass… Haven’t been able to focus the last few days. So i appreciate all of the extra effort everyone put in to help me out.