If I’ve understood correctly, I started the upper script, the list appeared, I then tried to copy one of the tags (<0/>) and then clicked on the entry for 0 <0/>, but I got the following error:
error “Can’t make {"<", "0", "/", ">"} into type record.” number -1700 from {“<”, “0”, “/”, “>”} to record
I’ve been working more with my script to create a tag shell and I think it might be the quickest and easiest thing:
set tag_ to ("<t/>") as string
tell application "System Events"
tell application "OmegaT" to activate
tell process "OmegaT" to keystroke tag_
key code 123 -- Left
key code 123 -- Left
delay 1
key code 124 -- Right
key code 124 -- Right
end tell
Your help has been fantastic and I really appreciate it.
I hope it’s ok to refer to another topic within this topic. If you don’t mind having a look at this, I would appreciate it. I’d like to be able to write a HowTo on this for the OmegaT site (and include you as the main source for solving the problem, if you don’t mind).
I have altered the coercion in the first script, and changed the copy operation to use “paste and retain style”, maybe that would help? please try that.
I thought other might need this as well, as it seems quirky to work with, that is why I asked you to post it, there is no need to reference me in this really. You are the instigator!
I am sorry to hear that, there are still some options left!
The first one is if you can see if you can find a menu choice (under the edit menu for paste and match style), this software being written in java, means that the keystrokes won’t necessarily conform 100%.
If we find that, then we are in luck!
If we aren’t, then we must find out if it is rtf you got there, and maybe we are in luck.
The second script I wrote, would “record” the attribute runs for bold for instance, but you will need it for bold and italic, and bold + italic, and plain,for it to make sense. I think that can be done, and it would be fun to manipulate the clipboard that way. Without you and me having to “record”
But first of all, see if you can find “paste and match style” or similiar somewhere in the docs!
also check out if you can copy style (best solution) and paste style.
On mac os x those are cmd-opt C and cmd-opt V, it would nice if those worked, because then I can provide a fix, by copy the style either before or after the insertion point, before pasting back the tag.
Hello if copy and paste style doesn’t work, then I need to know your OmegaT font, size weight, anything you can find about it, that shows up in the font dialog, for starters.
I might give it a shot, to try to construct the styled text on the clipboard. But I have not OmegaT to play with, nor will I install it, due to Java Libraries. But if you suplly the information, then I can perhaps make a solution work with TextEdit, that will also work with OmegaT.
In the Editor pane, text is displayed (as far as I can tell) in plain text. Only the tags are shown to indicate what formatting there might be (and this isn’t obvious from the tags themselves).
I’m sorry I can’t tell you more. I don’t have access to any of the programming specs.
Now this seems to get interesting! You have some text rendered as plain text in the editor pane, yet the text is rendered as RTF in your docx document when done.
We might be left in peril here!
But please copy some text from the Editor pane, that you are sure containing bold (or italic formatting), then run the script below, and post the output from the log window of AppleScript editor, if you get any.
set x to the clipboard as record
log scrap styles of x
Thanks for taking such an active interest in this. It really is super of you to do this.
Here is the output I got after copying a sentence from a text and then running the script you included:
error “Can’t get scrap styles of {«class utf8»:"Atreus ist Marktführer beim Einsatz von Interim Managern in Deutschland und unterstützt seine Kunden, wenn der Bedarf an Umsetzungssicherheit und -geschwindigkeit groß ist.", «class ut16»:"Atreus ist Marktführer beim Einsatz von Interim Managern in Deutschland und unterstützt seine Kunden, wenn der Bedarf an Umsetzungssicherheit und -geschwindigkeit groß ist.", string:"Atreus ist Marktführer beim Einsatz von Interim Managern in Deutschland und unterstützt seine Kunden, wenn der Bedarf an Umsetzungssicherheit und -geschwindigkeit groß ist.", Unicode text:"Atreus ist Marktführer beim Einsatz von Interim Managern in Deutschland und unterstützt seine Kunden, wenn der Bedarf an Umsetzungssicherheit und -geschwindigkeit groß ist."}.” number -1728 from scrap styles of {«class utf8»:“Atreus ist Marktführer beim Einsatz von Interim Managern in Deutschland und unterstützt seine Kunden, wenn der Bedarf an Umsetzungssicherheit und -geschwindigkeit groß ist.”, «class ut16»:“Atreus ist Marktführer beim Einsatz von Interim Managern in Deutschland und unterstützt seine Kunden, wenn der Bedarf an Umsetzungssicherheit und -geschwindigkeit groß ist.”, string:“Atreus ist Marktführer beim Einsatz von Interim Managern in Deutschland und unterstützt seine Kunden, wenn der Bedarf an Umsetzungssicherheit und -geschwindigkeit groß ist.”, Unicode text:“Atreus ist Marktführer beim Einsatz von Interim Managern in Deutschland und unterstützt seine Kunden, wenn der Bedarf an Umsetzungssicherheit und -geschwindigkeit groß ist.”}
I can send you a screenshot of the Editor interface if that will help.
Thank you, and that screenshot will not be necessary!
It was as I feared, there are two streams of characters here, one, which is what get what you type, since it manages to retain formatting information, like bold, and italcis. (If I have understood you right.) And the text shown again as pure ascii, presenting a view of the text in the editor window.
If there is any other place you process the text as RTF, then I’d like to know, as you did state that you wanted to keep the formatting, so, now I wonder, if there is any place you see this formatting.
But! I think this will work pretty good, anyway, if I change the first script to type the text!
I’ll be back with a solution doing just that, somewhat later.
property scriptTitle : "TagInserter"
set tagl to {{leadingnumber(0) & "<0/>"}, {leadingnumber(1) & "<1/>"}, {leadingnumber(2) & "<2/>"}, {leadingnumber(3) & "<3/>"}, {leadingnumber(4) & "<4/>"}, {leadingnumber(5) & "<5/>"}, {leadingnumber(6) & "<6/>"}, {leadingnumber(7) & "<7/>"}, {leadingnumber(8) & "<8/>"}, {leadingnumber(9) & "<9/>"}}
set res to choosesomething("Choose tag to insert", tagl, item 1 of tagl)
if res = false then return
set stringtoType to (characters 4 thru -1 of (res as text)) as text
tell application "OmegaT" to activate --
tell application "System Events"
keystroke stringtoType
end tell
on leadingnumber(n)
return text 1 thru 3 of (n & " " as text)
end leadingnumber
on choosesomething(aPrompt, listOfSomething, defaultSomething)
local theChoice
tell application "SystemUIServer"
activate
set theChoice to choose from list listOfSomething with prompt aPrompt with title my scriptTitle default items defaultSomething without multiple selections allowed and empty selection allowed
end tell
return theChoice
end choosesomething
I copied the source text, ran your script and then pasted in the desired tag, but it’s still being seen as an extra symbol rather than being interpreted as a tag.
We are not out of options yet! Because, it works if you type it?
Or is there anyway that works when you do it manually? I might try to use the keycodes, that may work, if it works when you type the tag.
property scriptTitle : "TagInserter"
set 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, 50, 76, 100}
-- Edward Mendelson http://macscripter.net/viewtopic.php?id=39030
set tagl to {{leadingnumber(0) & "<0/>"}, {leadingnumber(1) & "<1/>"}, {leadingnumber(2) & "<2/>"}, {leadingnumber(3) & "<3/>"}, {leadingnumber(4) & "<4/>"}, {leadingnumber(5) & "<5/>"}, {leadingnumber(6) & "<6/>"}, {leadingnumber(7) & "<7/>"}, {leadingnumber(8) & "<8/>"}, {leadingnumber(9) & "<9/>"}}
set res to choosesomething("Choose tag to insert", tagl, item 1 of tagl)
if res = false then return
set stringtoType to (characters 4 thru -1 of (res as text)) as text
set codestoHammer to {}
repeat with i in every character in stringtoType
set a to offset of i in charList as text
set end of codestoHammer to item a of codeList
end repeat
tell application "OmegaT" to activate --
tell application "System Events"
set frontmost to true
repeat with a in codestoHammer
if (contents of a) > 50 then
key code ((contents of a) - 50) using {shift down}
else
key code contents of a
end if
end repeat
end tell
on leadingnumber(n)
return text 1 thru 3 of (n & " " as text)
end leadingnumber
on choosesomething(aPrompt, listOfSomething, defaultSomething)
local theChoice
tell application "SystemUIServer"
activate
set theChoice to choose from list listOfSomething with prompt aPrompt with title my scriptTitle default items defaultSomething without multiple selections allowed and empty selection allowed
end tell
return theChoice
end choosesomething