• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Copy text to the clipboard
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copy text to the clipboard


  • Subject: Re: Copy text to the clipboard
  • From: kai <email@hidden>
  • Date: Fri, 2 Dec 2005 01:31:24 +0000


On 1 Dec 2005, at 18:37, John R. wrote:

I want to copy selected text into my script from ANY active application. I need to tell the current application to <get selection>, or I need to use GUI scripting via: <keystroke "c" using command down>. But I can't find the name of the active application or process...

tell application "System Events"
set x to (name of application processes whose frontmost is true)
display dialog item 1 of x
end tell
---> "ScriptEditor" when run under Script Editor;
---> "System Events" when run from the any application via the script menu.


How do I ask politely for the "process that was active just before I ran this script"?!
Is there a better way to copy selected text to the clip board?

Running from the Script Menu:

-----------

set appName to (info for (path to frontmost application))'s short name
tell application "System Events"
	set process appName's frontmost to true
	keystroke "c" using command down
end tell

-----------

Running as an application*:

-----------

tell application "System Events"
	tell (get first process whose frontmost is true)
		set visible to false
		repeat while visible
			delay 0.1
		end repeat
	end tell
	keystroke "c" using command down
end tell

-----------

* Launched, for example, from the Dock (to avoid making Finder the frontmost application).

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Copy text to the clipboard (From: "John R." <email@hidden>)

  • Prev by Date: Re: Shell script timing, regex
  • Next by Date: Re: Tiger broke the print command in quarkXpress - who else has notice this
  • Previous by thread: Re: Copy text to the clipboard
  • Next by thread: Re: Copy text to the clipboard
  • Index(es):
    • Date
    • Thread