Re: With Yosemite, can no longer get selected text of Google Chrome page
Re: With Yosemite, can no longer get selected text of Google Chrome page
- Subject: Re: With Yosemite, can no longer get selected text of Google Chrome page
- From: Charles Arthur <email@hidden>
- Date: Mon, 27 Oct 2014 15:40:28 +0000
Oh, and here’s the coda.
No matter what I’ve been trying,
++
tell application “Google Chrome”
set theselect to (copy selection of active tab of front window)
theselect
++
throws an error - the clipboard simply doesn’t seem to be set correctly. Setting the clipboard to the “copy selection” and then trying to make a variable equal to the clipboard fails. (ISTR deep reasons for this to do with typing, but don’t recall them. I’m sure Shane or Nigel will explain..)
Yet - and here’s the fun thing - my old script
++
tell application “Google Chrome”
set theselect to (selectedtext of me of “Google Chrome”)
theselect
end tell
++
now works perfectly **if invoked from the Scripts menu**. (This is because “of me” refers to the app that is running the script, which seems nominally to be the frontmost app if invoked as a script.) Try to do it from Script Editor, and it errors.
Seems that in the upgrade, some details of how Keyboard Maestro - the 2007 version - worked had to be reset. But that having been done, it’s all back to normal.
I do like the fact that these really old (in Apple terms anyhow) scripts and apps still work so many generations on. Though the whole “import Foundation” stuff, which has completely passed me by - I’ve not had any call to write Applescripts for a few years now.
> On 27 Oct 2014, at 00:59, G Wood <email@hidden> wrote:
>
>
>> The script goes, in part
>> ++
>> tell application "Google Chrome"
>> set theselect to (selectedText of me from "Google Chrome")
>> log "theselect: " & theselect
>> end tell
>> ++
>>
>> In Mavericks (and almost all earlier versions), this gives the selected text of the active tab.
>> In Yosemite, this gives “missing value”.
>>
>> Chrome’s library says it has a “copy selection” command -
>> ++
>> copy selection v : Copy text.
>> copy selection specifier : The tab to execute the command in.
>> ++
>>
>> Tried it. Doesn’t work. Neither “copy selection of active tab” nor “copy selection of active tab of front window” yields anything. (One errors, one returns no result.)
>>
>> In my desperation, I’ve even tried Javascript. Also doesn’t work. (Prefer not to use Javascript tbh.)
>>
>> So - how can I copy and paste selection in a Google Chrome window?
>
>
> I don't see a "selectedText" command but I do see the Chrome dictionary entry you cite. You appear to be using it incorrectly. It's not "copy selection of..." It's a verb/command directed at a tab.
>
> I also don't see any such entry as "active tab". Tabs belong to windows so you must speak to them via their window path (a tab id alone won't do).
>
> This works for me (you can condense this of course, I'm just being "tell" explicit here)...
>
> set cs to ""
> tell application "Google Chrome"
> tell window 1 -- or by it's id
> tell tab 2 -- or by it's id
> copy selection -- it's now in the clipboard
> end tell
> end tell
> end tell
> set cs to the clipboard -- copy clipboard to local var
>
> Manual (cmd-v) pasting now produces what I had selected, as does the use of the variable 'cs'.
>
> HTH
> -- Gary
>
best
Charles
On Twitter: http://twitter.com/charlesarthur
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden