Wednesday, June 26, 2019

#1 2019-01-09 08:31:08 am

ddinisco
Member
Registered: 2008-04-05
Posts: 33

Simple copy text not working

This simple script does not seem to work. I am simply trying to copy the selected text in Mail, but result keeps showing me the current clipboard (before running the script) and not the selected text in Mail. I tried this with TextEdit and on multiple computer and I get the same results. What is wrong with this?



activate "Mail"
tell application "System Events" to keystroke "c" using {command down}
delay 1 -- Without this, the clipboard may have stale data.

set theSelectedText to the clipboard


theSelectedText

Offline

 

#2 2019-01-09 08:57:12 am

haolesurferdude
Member
Registered: 2010-02-19
Posts: 119

Re: Simple copy text not working

Try this.

Applescript:

tell application "Mail"
   activate
   set theMessage to item 1 of (get selection)
   set theContent to the content of theMessage
   set the clipboard to theContent
end tell

Offline

 

#3 2019-01-09 10:17:06 am

ddinisco
Member
Registered: 2008-04-05
Posts: 33

Re: Simple copy text not working

Well that does copy the entire message. But I was hoping to copy only the selected text in the body of the email.

Offline

 

#4 2019-01-09 10:22:18 am

danaeugene
Member
Registered: 2017-04-02
Posts: 14

Re: Simple copy text not working

I tried to reply last night but must have posted to the wrong place.  I think the following script does what you are asking for.

Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Mail"
   activate
   tell application "System Events" to keystroke "c" using {command down}
end tell

delay 1

set theSelectedText to the clipboard

theSelectedText

Offline

 

#5 2019-01-09 10:45:59 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3460

Re: Simple copy text not working

Here is what I use for years.

Applescript:

set the clipboard to ""

tell application "System Events" to tell process "Mail"
   set frontmost to true
   keystroke "c" using {command down}
end tell

repeat # reduce the delay to the shortest required value
   if (the clipboard) > "" then exit repeat
   delay 0.1
end repeat

set theSelectedText to the clipboard

theSelectedText

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 9 janvier 2019 17:45:40

Offline

 

#6 2019-01-09 11:58:12 am

ddinisco
Member
Registered: 2008-04-05
Posts: 33

Re: Simple copy text not working

Success! Thanks so much!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)