Wednesday, August 10, 2022

#1 2022-05-19 08:02:21 am

gniec
Member
Registered: 2022-05-16
Posts: 4

unable to cut/paste log history

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
end tell

Offline

 

#2 2022-05-19 11:35:32 am

estockly
Member
Registered: 2009-01-03
Posts: 80

Re: unable to cut/paste log history

OK, First, you need to keep all commands to Script Editor and its windows inside a Script Editor tell block.

Applescript:

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.

Applescript:

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:

Applescript:


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:

Applescript:

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)

HTH

Last edited by estockly (2022-05-19 11:44:37 am)

Offline

 

#3 2022-05-23 04:50:45 am

gniec
Member
Registered: 2022-05-16
Posts: 4

Re: unable to cut/paste log history

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. 

Any other suggestions?

Offline

 

#4 2022-05-23 11:39:02 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2443

Re: unable to cut/paste log history

At least on Catalina, you can select/copy/paste Log history rich text following way.

Applescript:


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

Last edited by KniazidisR (2022-05-24 12:21:25 pm)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#5 2022-05-24 02:01:08 am

gniec
Member
Registered: 2022-05-16
Posts: 4

Re: unable to cut/paste log history

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]

Offline

 

#6 2022-05-24 12:24:45 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2443

Re: unable to cut/paste log history

I updated my script. See "-- ADDED"


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#7 2022-05-24 02:44:05 pm

robertfern
Member
Registered: 2011-11-29
Posts: 172

Re: unable to cut/paste log history

Here is a better version of the script.

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

Last edited by robertfern (2022-05-24 02:51:53 pm)

Offline

 

#8 2022-05-24 02:58:30 pm

robertfern
Member
Registered: 2011-11-29
Posts: 172

Re: unable to cut/paste log history

or since the TextEdit app is directly scriptable, you can do this

Applescript:

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

Last edited by robertfern (2022-05-25 09:49:19 am)

Offline

 

#9 2022-05-25 01:06:28 am

gniec
Member
Registered: 2022-05-16
Posts: 4

Re: unable to cut/paste log history

Thank you Robert,

Your changes were spot on and  have done the trick.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)