First post, by emendelson
EDIT: Newly rewritten script, transfers extended ASCII characters into DOSBox.
Dominus suggested this idea, and here it is. The following AppleScript is a script that will paste the OS X clipboard into DOSBox. This improved version includes some extremely elegant methods suggested by the experts at MacScripter.net, who deserve the credit for the good stuff.
How to use it: Copy the code into the OS X AppleScript Editor, save it as an application with a name like "PasteClipboardToDOSBox" or any other name you like. Optionally assign a hotkey that launches it in Butler, Quicksilver, or some other keyboard macro program. Or simply run it when DOSBox is running, in order to paste the OS X clipboard into DOSBox. Suggestions and improvements welcome.
-- Pastes the OS X clipboard into DOSBox-- By Edward Mendelson 3 July 2012-- try to determine DOS codepage for DOSBox according to Mac locale:set the codePage to "850" -- 850 for Europetryset macLocale to do shell script "defaults read -g AppleLocale"if macLocale is "en_US" or "en_CA" thenset the codePage to "437" -- 437 for North Americaend ifend try-- if you get the wrong results, then set correct codepage by uncommenting next line-- set the codePage to "437" -- either "437" or "850"tell application "System Events" to set tNames to (name of processes)set tClue to "DOSBox" -- looking for DOSBoxset appRunning to {}repeat with aName in tNamesif contents of aName contains tClue then set end of appRunning to contents of aNameend repeat-- error number -128if appRunning is {} thentell me to activatedisplay dialog "DOSBox not running." buttons {"OK"} with title "Paste into DOSBox" giving up after 5error number -128end ifset charList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "’", "-", "="}set codeList to {29, 18, 19, 20, 21, 23, 22, 26, 28, 25, 47, 39, 27, 24}set shiftList to {"“", "”"}set shiftCodeList to {39, 39}set kpCodes to {82, 83, 84, 85, 86, 87, 88, 89, 91, 92}-- Keypad key codes: KP0=82, KP1=83, KP2=84, KP3=85-- KP4=86, KP5=87, KP6=88, KP7=89, KP8=91, KP9=92tryset getClip to the clipboard as texton errorset getClip to " "end trytell application "DOSBox" to activatedelay 0.1tell application "System Events"repeat with i from 1 to count characters of getClipif (character i of getClip) is in charList thenset codeItem to my listPosition(character i of getClip, charList)set keyCodeNum to item codeItem of codeListkey code keyCodeNumelse if (character i of getClip) is in shiftList thenset codeItem to my listPosition(character i of getClip, shiftList)set keyCodeNum to item codeItem of shiftCodeListkey code keyCodeNum using {shift down}else if (ASCII number of (character i of getClip)) is greater than 127 thenset upperASCII to my getCharValueForDOS(character i of getClip, codePage)-- next lines by Nigel Garvey at MacScripter.nettell application "System Events"key down optionkey code (item (upperASCII div 100 + 1) of kpCodes)
key code (item (upperASCII mod 100 div 10 + 1) of kpCodes)key code (item (upperASCII mod 10 + 1) of kpCodes)key up optionend tellelsekeystroke (character i of getClip)end ifdelay 0.01tell application "DOSBox" to activateend repeatend tellon listPosition(thisItem, thisList)repeat with n from 1 to the count of thisListif item n of thisList is thisItem then return nend repeatreturn 0end listPositionon getCharValueForDOS(char, cPage)-- routine by DJ Bazzie Wazzie at MacScripter.netreturn (do shell script "/bin/echo -n " & quoted form of character 1 of char & " | iconv -f UTF8 -t CP" & cPage & " | od -A n -t u1") as integerend getCharValueForDOS