Need Quick Guidance

Hi folks.

I need some help with something. It’s worked before, but now it doesn’t.

I have the clipboard populated with a bit of text. I want to paste it into the current focus in an email for mail.app. Not at the end of the email, as I have a signature in there. I want to activate this window and just “paste” my text.

How can this be done? I had it working before, but now she isn’t…updated OS software or like that. I don’t know. Anyway, here are some suggestions.


tell application "System Events"
	tell process "Mail"
		delay 1.0
		keystroke "v" using command down -- ⌘V to paste the URL
		keystroke return
		keystroke return
	end tell
end tell

or…


tell application "System Events" to tell process "Mail"
	keystroke "v" using command down -- ⌘V to paste the URL
	keystroke return
	keystroke return
end tell

Neither works for me. Oh, I should explain that this is being launched using Launchbar. For some reason, the new outgoing email isn’t activated for some reason. If run in the AppleScript Editor, it works fine. No clue what to do, so any insight appreciated.

Cheers

Try starting your script with:


tell application "Mail" to activate ” just like that!

Already there:


tell application "Safari" to set myLoc to the URL of document 1
set the clipboard to myLoc
tell application "Mail" to activate
tell application "System Events" to tell process "Mail" -- GUI Scripting
	keystroke "v" using command down -- ⌘V to paste the URL
	keystroke return
	keystroke return
end tell

:slight_smile:
The code below works for me: But then, I have a new message open in a separate window, (I’m not using mail.app at the moment.)


tell application "Safari" to set myLoc to the URL of document 1
set the clipboard to myLoc
tell application "Mail"
	activate
	tell message viewer 1 to activate
end tell
tell application "System Events" to tell process "Mail" -- GUI Scripting
	keystroke "v" using command down -- ⌘V to paste the URL
	keystroke return
	keystroke return
end tell

this line is useless, only application objects respond to the activate command

…mmm clipboard manager, keystroke driven…

Since the script is supposed to work, maybe you should ask LaunchBar developers. Recently updated LaunchBar? Recently added something to LaunchBar that is messing up?

My experience says that kind of utilities will make you lose all the time (seconds) you’ve gained from using it with one silly problem like this. Unless you fear the utility and keep it simple and focused.

Yes, I’m sorry! :slight_smile: If anything I should have selected it. And it works great without that line too of course.

Well, this works great with the new Quicksilver too. Quicksilver is quite stable, as long as you don’t try to use the bookshelf at the time beeing. :wink:

But in all fairness, the script runner of Quicksilver doesn’t save properties…

hmm … since it seems that launchbar.app doesn’t seem to give mail the focus, how about something like this?


tell application "System Events"
	set frontmost of application process "Launchbar" to false 
	set visible of application  process "Launchbar" to false 
end tell

Before trying to address mail?

This may be a better alternative to the previous one, it is more precise.

At least this changes the focus from any other field of the message viewer into the text area for me!


tell application "Safari" to set myLoc to the URL of document 1
set the clipboard to myLoc
tell application "Mail" to activate

try
	tell application "System Events"
		
		tell application process "Mail" -- GUI Scripting
			
			tell its window 1
				set focused of scroll area 4 to true
				keystroke "v" using command down -- ⌘V to paste the URL
				keystroke return
				keystroke return
			end tell
			
		end tell
	end tell
on error e number n
	display dialog e & " " & n
end try


I can’t live without my Launchbar. I wanted to see if this script is valid and considered working. I’ve posted in the Launchbar forums, but for some reason it’s only happening to me and little to no reply. So I wanted to make sure the script was working before they had any front to blaming AppleScript or my code. On top of that, the nature of the AppleScript is often mistaken as a “new email” instead of “pasting HERE”.

Cheers. I appreciate the input.

Hello!

Did my last version work?

Working on it right now, actually. It created a new message, which I needed to take out. That’s not the goal of this. Now I’m having Launchbar issues. There’s always something.

Nah it’s not working. I run the script from Launchbar and nothing happens. The focus starts with a new email partially completed. I engage Launchbar and choose the script. Nothing happens.

Interesting that upon Command-V, it does demonstrate that it’s copied the URL, so the clipboard is behaving properly. The focus hasn’t left the new email. It’s the focus & paste that doesn’t seem to work. This is what I have currently:

tell application "Safari" to set myLoc to the URL of document 1
set the clipboard to myLoc
tell application "Mail" to activate
try
	tell application "System Events"
		tell application process "Mail"
			keystroke "v" using command down -- ⌘V to paste the URL
			keystroke return
			keystroke return
		end tell
	end tell
on error e number n
	display dialog e & " " & n
end try

What’s interesting is that no error comes up, it doesn’t work from Launchbar, yet it works from AppleScript Editor. Very strange.

Well I can’t really figure out any other way, well, what you could do, is to stuff the script into an automator service, and assign a keyboard shortcut in the keyboard preferences pane! :slight_smile:

Yeah it’s a strange one. I’ll repost in the Launchbar forums when I get a chance.

Thanks for your insight. I’m not going crazy.

Cheers

Well I got a reply from Obdev. Here’s the script, which avoids a lot. Quite an elegant solution:


tell application "Safari" to set myLoc to the URL of document 1
tell application "Mail" to activate
tell application "LaunchBar" to perform action "Copy and Paste as Plain Text" with string myLoc

Very good.

Cheers!

Hi!

I was curious about how it went, and how you eventually solved it! I am glad it worked out all right for you!
But Quicksilver doesn’t do that! :wink: (I am sure there are reasons for liking Launchbar! :slight_smile: )

That last item is a function in Launchbar.

“Copy and Paste as Plain Text” with string myLoc works right in AS as a single line. It’s perfect.