Error errOSAinvalidId in Applescript

I made the following code in Applescript :

tell application “Safari”
activate
open location “http://www.bcfi.be
tell application “Safari” to activate
end tell

I pasted this file (name = BCFIAppleScript.scpt) in a project

From within the project I called the script file.

Running the project seems to go fine : all I want what the script must do, was done.
But in the Xojo-Icon in the dock a red number 1 appeared.

I got the message :
Error in script ‘BCFIAppleScript.scpt’ (internal): OSACopyDisplayString returned errOSAInvalidID.

Every time I called the script from within the project, the number in the Xojo-icon was increased by 1

What did I wrong ?

That number is just telling you the number of unread messages in the system log.

Tx Kem. But what must I do to avoid or trap the error ?

I’m not sure it’s really considered an error as those types of messages appear in the system log all the time.

You could try “ignoring application responses” like this:

ignoring application responses
	tell application "Safari"
		activate
		open location "http://www.bcfi.be"
		tell application "Safari" to activate
	end tell
end ignoring

BTW, if your user doesn’t use Safari as their default browser, they won’t be happy with you.

I tried this out, but the problem is not solved.

BTW, I know the problem when the user doesn’t use Safari. I hope to solve this problem, when this one is solved.

Easier than you might think!

open location "http://timi.me"

That’s all you need :slight_smile:

Easier still…

ShowURL "http://www.bcfi.be"

No AppleScript
Works for OSX and Windows
Uses user default Browser

Thanks Kem, Tim and Dave.
I’m really surprised with the answer from Dave.
Wow, so easy and very simple.
And it works great !!!
Thanks you very, very much.

[quote=81664:@Antoon Verleysen]I made the following code in Applescript :

tell application “Safari”
activate
open location “http://www.bcfi.be
tell application “Safari” to activate
end tell

I pasted this file (name = BCFIAppleScript.scpt) in a project

From within the project I called the script file.

Running the project seems to go fine : all I want what the script must do, was done.
But in the Xojo-Icon in the dock a red number 1 appeared.

I got the message :
Error in script ‘BCFIAppleScript.scpt’ (internal): OSACopyDisplayString returned errOSAInvalidID.

Every time I called the script from within the project, the number in the Xojo-icon was increased by 1

What did I wrong ?[/quote]

I’m not certain that this is causing the messages in the IDE, but you have an error in your script, and that could be causing it. You can’t do this:

tell application “Safari”
[…]
tell application “Safari” to activate
end tell

That will cause an error, because application “Safari” has no application property named “Safari”. :slight_smile: Your first, plain “activate” does the trick nicely.

In plainer speak, in AppleScript, you don’t need to tell an application to tell itself to do something. :smiley: Just be direct and tell it yourself.

Eric, that second “tell” is unnecessary, but totally valid. You can switch targets at any time, and “tell” is how you do it.

I used that second ‘activate’ to give Safari the focus.
Without that, Safari was behind the window of my application.
But thanks anyway Eric

Kem: You know, I think you’re right. It’s poor form but perfectly valid.

Antoon: I’m surprised that the first activate wasn’t enough.

Eric : I gave the reason in my last post.
For my application I use the tip from Dave.
But I keep loving Applescript.
I also learned that sometimes, the solution is closer and easier without using Applescript.
Thanks for you all guys, for helping me so adequate and fast. You solved my problem.

[quote=81740:@Antoon Verleysen]I used that second ‘activate’ to give Safari the focus.
Without that, Safari was behind the window of my application.
But thanks anyway Eric[/quote]

Just to clarify, we weren’t saying the second “activate” was unnecessary, just using “tell application “Safari”” there. Once an application is the target (the first “tell”), you don’t have to use “tell” again for the same application.

Hi,

I stayed on that syntax:

on run {value1, value2} // your script code goes here end run

but before writing that answer, I checkd in the “UserGuide-Development.pdf” pdf and “discovers” that syntax (I certainly forgot it since ages…).

So: thank you all (question and answers).