Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Applications > AppleScript runs in Script Editor but not as saved application

AppleScript runs in Script Editor but not as saved application
Thread Tools
rw
Mac Enthusiast
Join Date: Dec 2000
Location: Kirkland, WA, USA
Status: Offline
Reply With Quote
Feb 7, 2004, 11:08 PM
 
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
Reply With Quote
Feb 7, 2004, 11:19 PM
 
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?

-
     
rw  (op)
Mac Enthusiast
Join Date: Dec 2000
Location: Kirkland, WA, USA
Status: Offline
Reply With Quote
Feb 8, 2004, 01:37 AM
 
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
Reply With Quote
Feb 8, 2004, 07:04 AM
 
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
Reply With Quote
Feb 8, 2004, 09:46 AM
 
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
     
rw  (op)
Mac Enthusiast
Join Date: Dec 2000
Location: Kirkland, WA, USA
Status: Offline
Reply With Quote
Feb 8, 2004, 10:54 AM
 
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
Reply With Quote
Feb 8, 2004, 11:36 AM
 
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
Reply With Quote
Feb 8, 2004, 12:42 PM
 
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. )
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:59 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2