Search:   Help

Navigation

Groups

LyX documentation

Edit

Shared groups

Links

Mac /

PasteFixUsingAppleScript

Categories: Mac
<< | Page list | >>

Using an AppleScript script to paste external clipboard contents into LyX version 1.5.1

1.  External clipboard issues in LyX 1.5.1

Some users of LyX 1.5.1 on Mac OS X have experienced problems pasting content cut or copied from external programs. For example, cutting text from TextEdit and trying to paste into LyX. LyX 1.5.1 on Mac OS X does not have the Paste External function anymore.

Cutting/copying LyX text and pasting into an external application works fine.

Note that pasting does work in LyX when you first start LyX. However, external clipboard data does not appear to be accessible once you've cut or copied within LyX.

2.  An AppleScript workaround

The AppleScript below uses the System Events API to paste a plain text version of the clipboard into the currently active LyX document. It is slow.

Presumably you just need to paste this into Script Editor, compile, save to the user script directory, and it should run.

Please remove this page, and all references, once the clipboard issue is resolved.

(* PasteToLyx
	Pastes the current Mac OS X clipboard to the current active LyX document
	as plain text.
	This is necessary as there is a bug in LyX 1.5.1 that prevents pasting
	data from external applications.
	Note--the pasting is slow, and seems to be character by character.

	For details on how this works, see
	* http://www.macosxhints.com/article.php?story=20040204170653788, for how to convert
	clipboard contents to plaint text,
	* http://forums.macosxhints.com/archive/index.php/t-28533.html, for using System Events
	to paste into an application,
	* "System Events and GUI Scripting" in AppleScript documentation, especially:
	"The GUI Scripting architecture is based on the accessibility support in Mac OS X,
 which must be enabled, in Mac OS X v10.4, through the AppleScript Utility.
 Prior to Mac OS X v10.4, GUI scripting was enabled through the “Enable access for assistive devices”
 checkbox in the Universal Access preference pane in System Preferences."
	* System Events is located in /System/Library/CoreServices; you can use the Script Editor to open
	up the dictionary associated with it, and under Processes Suite find info on keystroke, etc.
	* http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptX/index.html 
documents the above.

	Place this script into ~/Library/Scripts.  Access via Script Menu.
	Be sure to enable accessibility support.
	Both Script Menu and accessibility support can be enabled using the "AppleScript Utility.app"
	found in /Applications/AppleScript directory.

	See http://www.macdevcenter.com/pub/a/mac/2007/06/08/hit-and-run-launching-applescripts-with-keyboard-shortcuts.html
	for making this available via keyboard shortcut.

	Absolutely no warranty of any kind implied.  Use at your own risk.

	9/5/07 d grover
*)

tell application "Finder" to set frontApp to "LyX" -- talking to Finder, single-line tell, no need for end tell
tell application frontApp
	activate
	set clip to «class ktxt» of ((the clipboard as text) as record) -- making clipboard into plain text
	tell application "System Events" to keystroke clip -- painfully slow typing of text into application
end tell -- the frontApp tell.  The tell above is a single line tell.

Mac

Edit - History - Print - Recent Changes - All Recent Changes - Search
Page last modified on 2007-09-06 15:29 UTC