 |
 |
AppleScript runs in Script Editor but not as saved application
|
 |
|
 |
|
Mac Enthusiast
Join Date: Dec 2000
Location: Kirkland, WA, USA
Status:
Offline
|
|
I swear, trying to do anything with AppleScript is like banging your head against a wall.
I have a script that runs just fine if I open it in Script Editor and click the Run button. But if I save it as an application and run it, it doesn't work. What's up with that? Any AppleScript gurus out there who know how I might even go about debugging problem like that?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2001
Status:
Offline
|
|
You'd need to give more info. Other applescripts run fine as application? Can you boil down your script to a few lines to see what actually isn't working?
-
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Dec 2000
Location: Kirkland, WA, USA
Status:
Offline
|
|
I've managed to track down the part of the script that isn't working, and created a short test script that exhibits the same behavior:
Code:
on run
tell application "Finder"
set shoppingList to (desktop as string) & "ShoppingList.ooutline"
end tell
tell application "OmniOutliner"
open shoppingList
repeat with theRow in every row of document 1
if state of theRow as string is "checked" then
display dialog "OK"
end if
end repeat
end tell
end run
Anything inside the if block runs from Script Editor, but not if you run the script as an application. If you want to try this, you will need the OmniOutliner document, which you can find at http://home.earthlink.net/~khr/Shopp...t.ooutline.sit. Unstuff it and place it on your desktop. You will also, of course, need OmniOutliner. The version I have is 2.2.6.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
Hi,
Not sure what was wrong, but I've cleaned it up a bit (I think!) and it seems happier now:
p.s. you don't have to coerce everything to a string
- e.g. you can write: "if theRow is Checked" because OmniOutliner's Dictionary shows the various 'states' possible for a row:
state none/checked/indeterminate/unchecked -- The state of the check box for this row.
Code:
tell application "Finder"
set shoppingListFile to file "ShoppingList.ooutline" of desktop
end tell
tell application "OmniOutliner"
open shoppingListFile
repeat with theRow in every row of front document
if state of theRow is checked then
display dialog (topic of theRow) & " is checked"
end if
end repeat
end tell
(Last edited by Diggory Laycock; Feb 8, 2004 at 07:09 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Midwest
Status:
Offline
|
|
You do not need the Finder to set a variable to the file's path.
Code:
set shoppinglist to ((path to desktop as string) & "ShoppingList.ooutline")
CW says to avoid using the Finder in AS when possible.
Craig
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Dec 2000
Location: Kirkland, WA, USA
Status:
Offline
|
|
The script won't run at all if I don't set the path with the Finder. I get this error:
NSReceiverEvaluationScriptError: 4
I'm beginning to suspect that OO's implementation of AS is buggy, since I sometimes (but not always) get an error with this line:
Code:
tell application "OmniOutliner" to quit
This perverse bit of code solves that:
Code:
tell application "OmniOutliner"
try
quit
on error
quit
end try
end tell
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Oct 2001
Location: London
Status:
Offline
|
|
Originally posted by suthercd:
You do not need the Finder to set a variable to the file's path.
Code:
set shoppinglist to ((path to desktop as string) & "ShoppingList.ooutline")
CW says to avoid using the Finder in AS when possible.
Craig
Who's CW?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Midwest
Status:
Offline
|
|
Conventional Wisdom.
New scripters think that the Finder needs to be called while many of the classes and commands that folks use are actually a part of the Standard Additions scripting addition.
Take a look at the Finder dictionary and then the Standard Additions dictionary. The latter has a lot more capability.
Applescript now can script System Events and my sense of stuff is that scripting the Finder is being deprecated. There are a few classes that are Finder specific and not found In system Events but not many.
Craig
(Last edited by suthercd; Feb 8, 2004 at 12:55 PM.
)
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|