testing visible status of a process

tell application "LaunchBar"
	hide
	set selection as text to "what"
end tell
tell application "LaunchBar"
	hide
	delay 1
	activate
	set thesel to (selection as text)
	set the clipboard to thesel
end tell

I run this script from LaunchBar. This script works properly. I can see that the clipboard that the clipboard is “what”. I am just explaining the behaviour of “LaunchBar” with this script. It understands hiding and activating itself.

tell application "LaunchBar" to hide
delay 2
tell application "System Events"
	if visible of process "LaunchBar" is false then
		tell application "LaunchBar"
			activate
		end tell
		end if
end tell
delay 2
repeat
	tell application "System Events"
		say 1
		try
			if visible of process "LaunchBar" is false then
                               say 2
				tell application "LaunchBar"
					set thesel to selection
					exit repeat
				end tell
				say 3
			end if
		on error e
			tell me to activate
			display dialog e
		end try
		set the clipboard to thesel
	end tell
end repeat

This script fails when run from both Script Editor and LaunchBar.
When run from the Script Editor (or LaunchBar), I hear 1 and 2 but not 3.
Infact, I should not hear 2 because, I can see that Launchbar is visible and even frontmost.
Any alternate ways to accomplish the same task. My idea is to use the time while LaunchBar is visible to get a file which will be a variable in an applescript. If the script works, I will be able to collect multiple variables.
(Please do not provide me any LaunchBar tricks to do these things. My script does not require those)

The script works as expected on my system when run from scripteditor. It says “one” and shows an alert that the variable theSel isn’t defined. When run from Launchbar, it says “one”, but won’t show the variable alert. Have you tried “frontmost of process” instead of “visible of process”?

I’ve had problems running scripts from Launchbar that tells Launchbar to hide or activate. The results vary to say the least. Sometimes the app hides/activates, sometimes not.

For instance, this script refuses to hide Launchbar on my system. But if move the hide line and throw in a couple of “say 1” before and after it, it works as expected:

http://forums.obdev.at/viewtopic.php?f=24&t=3441

Just out of curiosity, are you trying to do the quicksilver comma-trick?

/backelin

The script works as expected on my system when run from scripteditor. It says "one" and shows an alert that the variable theSel isn't defined. When run from Launchbar, it says "one", but won't show the variable alert.

I hear 1,2 from LB also just like in Script Editor. I am using LB 5 on Leopard.

yes, i did. I don’t remember what happened but obviously it was not working.

I haven’t had a single problem. I have modified all by Quicksilver scripts to make them work with LaunchBar. I begin my scripts with
tell app Launchbar to hide
and end them with
set selection to
or
set selection as text to

But you can also try:

tell app "LaunchBar"
open location "x-launchbar:hide"
end tell

(I have already written two scripts for LaunchBar which substitute the comma-trick. Nothing great but they are still bettter than ClipMerge.)
But yes, I am trying an alternative for the comma trick. I am trying to collect arguments in the middle of the script. And trying to see if I can collect such multiple arguments one after another.
For example, sending a mail requires arguments like
1.subject, body --can be separated by delimiter like comma and hence one argument
2. attachment
3. contact name
I am currently using ClipMerge and making applescript check whether the paragraphs of ClipMerge contents begin with “/” to separate paths (attachments) and contact name. But with ClipMerge, I am never really sure of what items I am working on. I guess, I will just use the two scripts that I wrote. Because all this (talking about the script i posted here in my first post)is a lot of trouble. It would have been great if it had worked though!!