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.
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
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
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! 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.
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
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”.
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!
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
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! (I am sure there are reasons for liking Launchbar! )