From: Brian M. <ma...@ex...> - 2006-01-19 03:26:36
|
I want to put arbitrary ASCII strings onto the clipboard (including NULs, control chars, etc.). I could do this: def copy(string) applescript = "set the clipboard to \"#{string}\"" OSX.do_osascript(applescript) true end But I see no way in applescript to quote peculiar characters (other than tab and newline). As a hack, I can convert the string into UTF-8, then back into a string, and paste that: def to_hex(string) string.unpack('c*').collect { | char | sprintf("%x", char)}.join end def copy(string) applescript=" set unicode_version to \xc7data utf8#{to_hex(string)}\xc8 set the clipboard to unicode_version as string " OSX.do_osascript(applescript) true end (The funny quoted characters are the chevrons applescript uses to surround unprintable stuff.) This happens to work even for Mac-Roman characters (those with the high-order bit set), though I think that's an unintended side-effect of the way "as string" works. I'd rather go through a lower-level API than through applescript, but I'm ignorant enough of OSA and other topics specific to the Mac that I can't find what that would look like. Can anyone help? ----- Brian Marick, independent consultant Mostly on agile methods with a testing slant www.exampler.com, www.testing.com/cgi-bin/blog Book in progress: www.exampler.com/book |