The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   OS X Developer (http://hintsforums.macworld.com/forumdisplay.php?f=27)
-   -   AppleScript: I want to quit the script editor. (http://hintsforums.macworld.com/showthread.php?t=30478)

yellow 11-10-2004 12:24 PM

AppleScript: I want to quit the script editor.
 
Greetings,

I know nothing about AppleScripting and I'm under a serious time constraint, so don't have the time to learn what I need to learn to make it work the way I want, so I'm here begging some help off you already-experts.

The Background:
I am forced to force my users to use Lotus Notes on the Mac. Lotus Notes (6.5.2) has internal (very poor) handling of URLs. You can specifiy other browsers to use, such as IE (need I say anything more?), or Netscape (Classic only, don't you know), or "Other". Well, "Other" doesn't work for anything at all. So I decided to try and create a simple AppleScript that would open Safari and see if that would work. It does!

The Script:

tell application "Safari"
activate
end tell

The problem is, it opens the Script Editor when it runs. And, I don't want it to open the Script Editor at all. I tried saving it as all the other options, but when any of the scripts/apps run, it either opens the Script Editor, or doesn't do anything at all. For example, I saved it as an Application. Then pointed Notes at it, I click on a URL link, and the script opens in the dock and then closes, Safari never actually opens. I tried adding some line that told the Script Editor to automatically quit, but I get an error saying that it cannot quit when it's running the script.

Does anyone have any insight into this? Thanks!

irishomac 11-10-2004 12:27 PM

Applescript
 
Can you post the actual applescript? What options are you choosing when saving the script file?





irishOmac

yellow 11-10-2004 12:38 PM

Lotus Notes cannot deal with "Application Bundles" so they don't work, and it won't even recognize "Script Bundles", so I'm left with "Script", "Application", and "Text".

script 1:
Code:

tell application "Safari"
activate
end tell

When trying to tell the Script Editor to quit it becomes:

script 2:
Code:

tell application "Safari"
activate
end tell
tell application "Script Editor"
quit
end tell

I've tried ALL the settings/options when saving. All of them.
It's quite frustrating. I'm guessing that for whatever reason, the problem is with Lotus Notes (hatehatehatehate).


I can save the "script 1" as an app. Alone, the script works great, I can double click the .app and Safari opens. I can point Notes at the .app and when I click on a URL, the script runs (Script Editor does NOT open), and then quits, and Safari never opens.

The only way I've gotten Safari to work so far is just saving it as a "Script" (or "Text"), and it doesn't matter if I choose "Run Only" or nothing at all as an option, I click on a link in Notes, Script Editor opens and runs the script, and Safari Opens. Script Editor stays open. My users will be confused, which I why I wanted Script Editor to go away.

shufflebear 11-10-2004 12:47 PM

1 Attachment(s)
I have a script that will do exactly what you are looking for. I can't remember where I got it maybe from the Notes Forums. I have attached it to this note. Place the file somewhere on your mac and in the browser setting in Notes point to the script. Works great for me !.

Andrew

irishomac 11-10-2004 12:50 PM

Try this
 
tell application "Safari"
activate
end tell

delay 5

tell application "Script Editor"
quit
end tell

You may need to adjust the delay time to make Lotus happy, but try that and see if it works. If it doesn't let me know

irishOmac

yellow 11-10-2004 12:55 PM

Thanks for the replies.
I had the same though and I'd already tried that but still got the error "The document can't be closed while the script is still running."

I suppose I could call yet another applescript app to run and kill Script Editor?

What a messy kludge though..

irishomac 11-10-2004 01:01 PM

Applescript
 
You can put a script to open the script app in Lotus notes. When the lotus notes script calls the other script app that one can open Safari and close Script Editor if needed.


That is strange.

yellow 11-10-2004 01:12 PM

Ah, ShuffleBear, thanks, I missed your post, that's exactly what I'm looking for!

The code for that script is:
Code:

on open target_URL
        tell application "Safari"
                if (count of windows) is greater than 0 then
                        my new_tab()
                        try
                                open location target_URL
                        end try
                else
                        try
                                open location target_URL
                        end try
                end if
        end tell

Though, in it's raw form as a .app, it does not work. Oh well, I give up. Thanks!

hayne 11-10-2004 01:34 PM

yellow:
I'm not sure I understand the problem, but if it is that Lotus Notes doesn't like executing .app bundles, maybe you could wrap your AppleScript into some other kind of executable. You could use one of the 3rd-party utilities that make double-clickable apps out of scripts but maybe you would have the same problems with the app that they create.

But maybe just a shell script would work?
You could run your AppleScript code from a Perl script for example by using something like what is shown in this old thread:
http://forums.macosxhints.com/showth...04&#post131204
where you could use the runAppleScript function to run the AppleScript code as illustrated by the getSourceOfFrontWebPage and showWebpage functions in that example.

yellow 11-10-2004 01:44 PM

I tried a shell script but couldn't get the URL passed to the script properly.
I thought about trying perl or java, but don't know jack about either. I'll give that thread a perusal and see if I can make it work for me. Thanks for the help all!

hayne 11-10-2004 01:53 PM

Quote:

Originally Posted by yellow
I tried a shell script but couldn't get the URL passed to the script properly.

The command-line arguments to a Bash script are available in the script as $1 $2 etc
For a Perl script, they are $ARGV[0] $ARGV[1] etc

yellow 11-10-2004 02:18 PM

Quote:

Originally Posted by hayne
The command-line arguments to a Bash script are available in the script as $1 $2 etc

That's what I tried, but I'm sure I was using it incorrectly.

I was trying to echo $1 and pipe that into open -a "Safari".
I also tried echo $1 and piped that into osascript.

I think the echo is where I'm running afoul there. Safari opens but the URL isn't passed to it.

yellow 11-10-2004 03:16 PM

Well, I figured out why an applescript.app wasn't working. Apparently Applescript is all F'd up. My simple applescript was running other applescripts instead. In this case, a colorsync applescript. When I removed that one, it moved on to "import email into Entourage". After removing that one, it started launching iTunes. You get the idea.

The ONLY way to make it work properly was to remove all other applescripts from the hard drive. Bizarre.

nkuvu 11-10-2004 03:21 PM

Well from a command line, the echo with pipe doesn't work for me. However, the command
open 'http://www.google.com'
opened Google in Safari (since Safari is my default browser).

So maybe in the bash script it should be open $1 ?

Just wild guessing here...

yellow 11-10-2004 03:37 PM

Good idea..

Doesn't work ("Unable to launch program", same problem when trying to point it at a .app bundle). I tried some variations but it doesn't seem to like the $1 variable.

hayne 11-10-2004 04:09 PM

Quote:

Originally Posted by yellow
Doesn't work ("Unable to launch program", same problem when trying to point it at a .app bundle). I tried some variations but it doesn't seem to like the $1 variable.

Please show us your script.
The following bash script (saved in a file named "open_this") works fine for me when I invoke it via the command (in Terminal):

./open_this http://www.google.com

Code:

#!/bin/sh

echo "About to open $1"
open $1


yellow 11-10-2004 04:24 PM

Yes, your script definitely works.

But it doesn't work with Notes. Looking back at what I fiddled with, it's all worthless uses of attempting to echo $1 and pipe it into open -a Safari, but the URL isn't passed.. Safari opens, but I'm getting the wrong info from $1.

For example, Notes pointing at a script with:

#!/bin/sh
echo $1 > /Users/yellow/Desktop/test.txt

And then clicking on the URL in Notes gives me:

yellow% more test.txt
-psn_0_53477377

hayne 11-10-2004 04:39 PM

Quote:

Originally Posted by yellow
For example, Notes pointing at a script with:

#!/bin/sh
echo $1 > /Users/yellow/Desktop/test.txt

And then clicking on the URL in Notes gives me:

yellow% more test.txt
-psn_0_53477377

I think the problem is merely that the URL that you want is not the first argument in the command execution.
If you watch the output of 'ps axww' when Notes invokes the application/script, you will see that the "psn_xxxxx" is part of the command line.
You need to find out which argument is the one containing the URL that you want. It probably is $2, but maybe there are other arguments we don't know about.
Try the following script to find out:
Code:

#!/bin/sh
filename="/Users/yellow/Desktop/test.txt"
/bin/rm -f $filename
echo "arg1: $1" >> $filename
echo "arg2: $2" >> $filename
echo "arg3: $3" >> $filename
echo "arg4: $4" >> $filename

(The >> makes it append to the file instead of replacing the whole contents as would happen with a single > )

yellow 11-10-2004 04:43 PM

I tried that too.. and they were all blank, but I had only tried to $3, so I'll put in some more and see what comes out.

yellow 11-10-2004 04:45 PM

I tried all the way to $10 and got:

yellow% more test.txt
arg1: -psn_0_54919169
arg2:
arg3:
arg4:
arg5:
arg6:
arg7:
arg8:
arg9:
arg10: -psn_0_549191690

yellow 11-10-2004 04:46 PM

If I go further, all I get are:

arg11: -psn_0_550502411
arg12: -psn_0_550502412
arg13: -psn_0_550502413
arg14: -psn_0_550502414
arg15: -psn_0_550502415
arg16: -psn_0_550502416
arg17: -psn_0_550502417
arg18: -psn_0_550502418

<sigh>

Thanks for all the help!

hayne 11-10-2004 05:31 PM

I did some googling and found a macosxhints article (which yellow has evidently seen since he added a comment to it today) and two Lotus Notes forum discussions:
http://www.macosxhints.com/article.p...30627172202953

http://www-10.lotus.com/ldd/nd6forum...5?OpenDocument

http://www-10.lotus.com/ldd/nd6forum...0?OpenDocument

The macosxhints article suggests a strange workaround - selecting a blank document file (instead of an application). Did you try this yellow?
There is also a comment by someone who supplied a URL (no longer valid) for an AppleScript to make this work.

The first of the Lotus forums links has an AppleScript from Lotus Support that people have apparently had success with.
The second of the Lotus forums links has a submission by the same person who wrote the script mentioned in the comment to the macosxhints article.

Yellow:
I would go back to trying the straight AppleScript solution (save as Application) and contact Lotus support if it doesn't work.

I don't understand why you would get all those "psn_xxx" arguments in the command line of the application invoked by Notes. Usually there is one such argument that I think indicates the process number for backward compatibility with Process Manager software (used in Classic).

yellow 11-10-2004 09:45 PM

I wonder if part of this problem is the fact that Notes is a carbonized app..

yellow 11-10-2004 09:51 PM

Currently I'm using the AppleScript method, but I cannot save it as an app. I found out why. For whatever reason, when the app is invoked, it runs random applescripts. If I remove every other apple script from the Mac, the app runs great. I noted this a little further up in this thread.

http://forums.macosxhints.com/showpo...6&postcount=13

It's still not clear to me if this is a problem with Notes, or that Applescript is screwy. Someone mentioned something about prebinding, but that seems far-fetched to me. I talked with some other Mac heads who use Notes and they were all seeing the same thing.

But for the moment, Applescript works, provided my users don't mind the script editor running.

Thanks for the continued help!

hayne 11-11-2004 01:30 AM

Quote:

Originally Posted by yellow
Currently I'm using the AppleScript method, but I cannot save it as an app. I found out why. For whatever reason, when the app is invoked, it runs random applescripts.

That is very weird.
But recalling what was said in that macosxhints article - that you could point Notes to a document file and it would work to run the application associated with that document - I'm thinking that what Notes might be doing is searching for an app with a specified creator code and then running that app.
If this is the case, you might be able to solve your problem by saving your script as an application but then using one of the many 3rd-party utilities that can edit creator codes and change the creator code to something unique. You would do this before you point Notes to this app. That way (if my theory is right) it would be sure to run the correct AppleScript since only yours would have the creator code it was looking for.

Quote:

But for the moment, Applescript works, provided my users don't mind the script editor running
So, the situation seems to be that the script will work if it runs from within the Script Editor, but not stand-alone.
This is similar to that described in this macosxhints article:
http://www.macosxhints.com/article.p...00401270713117
where people seemed to identify the problem as related to the format used by Script Editor for compiled apps.
They recommended removing the resource fork of the .app file

bunnz 11-11-2004 10:21 AM

yellow:

Quoting hayne -

"I'm thinking that what Notes might be doing is searching for an app with a specified creator code and then running that app.
If this is the case, you might be able to solve your problem by saving your script as an application but then using one of the many 3rd-party utilities that can edit creator codes and change the creator code to something unique. You would do this before you point Notes to this app. That way (if my theory is right) it would be sure to run the correct AppleScript since only yours would have the creator code it was looking for."

Given the behavior yellow describes, hayne is likely on the right track to solving the problem for an AS application.

Change the creator type (as he suggests) to a unique four character signature. If the app has a resource fork, open the app with a resource editor and set the BNDL signature to the same as the creator. Open the plst resource and scroll most of the way down til you find 'aplt' in the XML code. Replace 'aplt' with your unique signature. Save changes and point notes to the script app. Whut hoppen?

For a script app with no resource fork, I think you change the .plist in the same manner as for the plst resource above... but I don't have much experience with app bundles.

I _think_ Notes should be able to 'see' the recreatored app.

Let us know if this works.

Peter B.

-----

hayne 11-11-2004 10:38 AM

Quote:

Originally Posted by bunnz
If the app has a resource fork, open the app with a resource editor and set the BNDL signature to the same as the creator. Open the plst resource and scroll most of the way down til you find 'aplt' in the XML code. Replace 'aplt' with your unique signature.

You can do this much more easily by using one of the specialized utilities for editing type & creator code - e.g. XRay (http://www.brockerhoff.net/xray/)


All times are GMT -5. The time now is 05:37 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.