I have been trying to create a script to cut and past the replies window of Log History or debugging purposes. I have tried various routes with out any success.
I have even tried to identify the “Log History” window as part of the script as well as instructions to make it the frontmost window.
It seems to fail at the Select All / Copy stage.
Any help to resolve this issue would be greatly appricated.
My latest code is:
tell application “Script Editor” to activate
set theWindow to the first item of (get the windows whose name is “log history”)
set index of theWindow to 1
activate window theWindow
set frontmost to true
delay 2.5
tell application “System Events”
–set index of theWindow to 1
–activate window theWindow
set uiScript to “click checkbox "Replies" of group 2 of splitter group 1 of window "Log History" of application process "Script Editor"”
select checkbox "Replies" of group 2 of splitter group 1 of window "Log History" of application process "Script Editor"
set index of theWindow to 1
activate window theWindow
delay 5
tell process "script Editor"
tell text field 1 of group 1 of row 1 of outline 1 of scroll area 1 of group 1 of splitter group 1 of window "Log History" of application process "Script Editor"
tell checkbox "Replies" of group 2 of splitter group 1 of window "Log History" of application process "Script Editor"
delay 1
tell window the window to key code 0 using {command down}
tell window the window to key code 8 using {command down}
delay 2
end tell
tell application "TextEdit" to activate
tell application "System Events"
tell process "TextEdit"
keystroke "v" using {command down}
end tell
end tell
end tell
end tell
OK, First, you need to keep all commands to Script Editor and its windows inside a Script Editor tell block.
tell application "Script Editor"
--all your commands to SE, its windows and documents go here
end tell
In your sample, commands to the window were not going to SE.
tell application "Script Editor"
activate
set theWindow to window "log history"
set index of theWindow to 1
log properties of theWindow
end tell
(frontmost doesn’t work on windows, but index does)
Your system events UI stuff looks OK, but I try to avoid it. If you really need it it should start like this:
tell Application "Script Editor" to activate
tell application "System Events"
tell its process "Script Editor"
--the rest of your commands go here
end tell
end tell
end tell
But, rather than use UI to try to get the text from the log window, you might be better served by getting the document’s log:
tell application "Script Editor"
tell its document 1
set myLog to event log
end tell
end tell
One last thing, on this forum, your posts will look better and be easier to respond to if you put all the AppleScript samples inside the “AppleScript” tag.(That’s what makes the “Open this Scriplet in your Editor:” option)
Thank you for your suggestions but I am still having an issue. Even with your suggestions all that I is a copy of the script and not the Log History replies as a text file.
At least on Catalina, you can select/copy/paste Log history rich text following way.
tell application "Script Editor" to activate
tell application "System Events" to tell process "Script Editor"
set frontmost to true
repeat until window 1 exists
delay 0.1
end repeat
keystroke "l" using {command down, option down}
repeat until window "Log History" exists
delay 0.1
end repeat
tell window "Log History"
click checkbox "Replies" of group 2 of splitter group 1
select text area 1 of scroll area 1 of group 1 of group 2 of splitter group 1
end tell
keystroke "a" using command down -- ADDED
delay 1 -- ADDED
keystroke "c" using command down
end tell
tell application "TextEdit" to make new document
tell application "System Events" to tell process "TextEdit"
set frontmost to true
repeat until window 1 exists
delay 0.1
end repeat
keystroke "v" using command down
end tell
Thank you for your help but I still run into the same issue.
It copies the script as written but not the replies window. The following is an ac
tual cut and paste from the replies window and you can see the comments inserted by the script. I would like to incorporate this as a handler for a script to get the menu items from an application.
[AppleScript]
tell application “System Events”
set frontmost of process “Script Editor” to true
exists window 1 of process “Script Editor”
→ true
keystroke “l” using {command down, option down}
exists window “Log History” of process “Script Editor”
→ true
click checkbox “Replies” of group 2 of splitter group 1 of window “Log History” of process “Script Editor”
→ checkbox “Replies” of group 2 of splitter group 1 of window “Log History” of application process “Script Editor”
select text area 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of window “Log History” of process “Script Editor”
→ text area 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of window “Log History” of application process “Script Editor”
keystroke “c” using command down
end tell
tell application “TextEdit”
make new document
→ document “Untitled 3”
end tell
tell application “System Events”
set frontmost of process “TextEdit” to true
exists window 1 of process “TextEdit”
→ true
keystroke “v” using command down
end tell
/applescript]
tell application "Script Editor" to activate
tell application "System Events" to tell process "Script Editor"
--set frontmost to true -- NOT NEEDED
repeat until window 1 exists
delay 0.1
end repeat
keystroke "l" using {command down, option down}
repeat until window "Log History" exists
delay 0.1
end repeat
tell window "Log History"
click checkbox "Replies" of group 2 of splitter group 1
select row 1 of outline 1 of scroll area 1 of group 1 of splitter group 1
keystroke "a" using command down -- ADDED
delay 0.5
set myreplies to value of text area 1 of scroll area 1 of group 1 of group 2 of splitter group 1
end tell
tell me to set the clipboard to myreplies
end tell
tell application "TextEdit" to make new document
tell application "System Events" to tell process "TextEdit"
set frontmost to true
repeat until window 1 exists
delay 0.1
end repeat
tell window 1
set value of text area 1 of scroll area 1 to myreplies
end tell
end tell
or since the TextEdit app is directly scriptable, you can do this
tell application "Script Editor" to activate
tell application "System Events" to tell process "Script Editor"
--set frontmost to true
repeat until window 1 exists
delay 0.1
end repeat
keystroke "l" using {command down, option down}
repeat until window "Log History" exists
delay 0.1
end repeat
tell window "Log History"
click checkbox "Replies" of group 2 of splitter group 1
select row 1 of outline 1 of scroll area 1 of group 1 of splitter group 1
keystroke "a" using command down -- ADDED
delay 0.5
set myreplies to value of text area 1 of scroll area 1 of group 1 of group 2 of splitter group 1
end tell
end tell
set the clipboard to myreplies -- moved this line outside the tell block to simplify
tell application "TextEdit"
make new document
repeat until window 1 exists
delay 0.1
end repeat
set text of document of window 1 to the clipboard
end tell