Can I use COM to access any application

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
tczucker
Posts: 18
Joined: 05 Mar 2020, 14:29

Can I use COM to access any application

Post by tczucker » 17 Mar 2020, 12:46

I am not very well versed in AHK, I have created several scripts and use them often, but my problem is that when I create them I generally am using very unreliable send [key] commands. This leads to all kinds of trouble. More recently I received a lot of help getting one of my older scripts to work using COM commands, this was much better (thanks to forum member awel20). I tried using an older script to access another application, but it fails terribly.

I apologize in advance for not having immersed myself in the AHK manual, but I am finding it difficult going - is there any way to download a PDF of it?

Can I use com or something similar here as well? Any help would be appreciated?

Something that is probably not related, in this script the msgbox appears before the backup has completed. Shouldn't it execute the script before going to the next line, or does the include statement do something different?

Code: Select all

; ------------------------------------------------------------------------------------------------------------------------------
; ----- This script performs the following actions, with user input for the 3rd and 4th actions                            -----
; -----																			-----
; -----     1. assigns the window key + w as the hotkey for the script								-----
; -----     2. backs up the open library file to an enlx compressed file								-----
; -----     3. imports new publications from an email											-----
; -----     4. Sets the title matching mode for a partial beginning string								-----
; -----     5. Checks for the existence of the window for EndNote X9, then activates that window			-----
; -----     6. Sends the exclude codes to the custom 8 field of all records in the default view				-----
; -----     7. Sends the source information to the Reveiewed Items field for all refs shown					-----
; -----     8. Copies the Accession Number (pubmed ID) to the Label field (so ref dupe searching can use it)	-----
; -----     9. Copies the record number to the call number field for consistancy						-----
; -----     10. replaces any instances of https orcid.org /  Broken Link for safety or http orcid.org /  Broken Link for safety in the custom 5 field with blank	-----
; -----     11. Replaces any carriage returns in the custom 5 field with ", "							-----
; -----     12. Replaces any carriage returns in the Tertiary Title (grant info) field with ", "					-----
; -----                                                                                                                                                       -----
; ------------------------------------------------------------------------------------------------------------------------------
; -----                                                                                                                                                      -----
; -----                                This script was written by Thomas Zucker-Scharff                                               -----
; -----                                                                                                                              			       -----
; ------------------------------------------------------------------------------------------------------------------------------
; 
Return
;
#w:: ; assign [Win]+w to script
;
#include j:\scripts\backup for inclusion.ahk ; backup library file before continuing
;
MsgBox, 4, Backup is complete, do you wish to continue?
IfMsgBox, No
	Return
#include j:\scripts\Pubs_from_email.ahk ; import publications into database
MsgBox, 4, Import is complete, do youi wish to continue? 'n'n 	(This will initiate the update script)
IfMsgBox, No
	Return
;
SetTitleMatchMode,1 ; title must begin with String
IfWinExist,EndNote X9
{
; ------------------------------------------------------------------------------
; ------------------ replace excludes in custom 8 field ---------------------
; ------------------------------------------------------------------------------
   WinActivate
   Send !t ; send alt t to access the tools menu
   Send {c 2} ; send to c keystrokes to access the change submenu
   Send {ENTER} ; send enter key to choose menu
   Send {c 7} ; send the c key 7x to choose the Custom 8 field
   Send {TAB 2} ; send the tab kay twice to position in change area
   Send {Down 2} ; send down key twice to choose "replace whole field with:"
   Send {TAB} ; to get to text field
; -------------------------------------------------------------------------------------------------
; ----- The following code requests input from user then sends to the custom 8 field -----
; -------------------------------------------------------------------------------------------------
   InputBox, excludes, Enter exclusions for selected records, Excludes:,,,,,,,aftergrant2012_09 after2014SFURequest after2014Progressreport after2015Progressreport after2016Progressreport after2017Progressreport after2018infopackets after2018sfurequests after2018Progressreport aftermulti2018 after2018ImpactFactor after2018pgldrinfopackets after2018latestpubs after2018selectedpubs after2018finalcount after2018submission after2019sv after2019_RPPR_Printoutfor_IDG after2019plreports after 2020RPPRpubsforPL
   MsgBox, 4, The exclude text is %excludes%
   IfMsgBox, No
	Return
   Send  %excludes% ; enter text for excludes in custom 8 field
   ; ----------------------------------------------------------------------------------------
   Send {TAB}
   Send {ENTER 2}
   ; ------------------------------------------------------------------------------------
   ; ----- The following code checks to see if update window has closed yet -----
   ; ------------------------------------------------------------------------------------
   SetTitleMatchMode,1
   WinWait, Changing Fields... ; wait until update window closes
   WinWaitClose ; wait until update window closes
   ; ----------------------------------------------------------------------------
   Send {Enter}
; finished section 1 - entering excludes
}
SetTitleMatchMode,1 ; title must begin with String
IfWinExist,EndNote X9
{
   WinActivate
   Send !t ; send alt t to access the tools menu
   Send {c 2} ; send to c keystrokes to access the change submenu
   Send {ENTER} ; send enter key to choose menu
   Send {r 4} ; send the r key 4x to choose the Reviewed Item field
   Send {TAB 2} ; send the tab kay twice to position in change area
   Send {Down 2} ; send down key twice to choose "replace whole field with:"
   Send {TAB} ; to get to text field
   ; -------------------------------------------------------------------------------------------------------
   ; ----- The following code requests input from user then sends to the Reviewed Item field -----
   ; -------------------------------------------------------------------------------------------------------
   InputBox, pubsource, Enter publication source:, Publication Source:,,,,,,,,2020 from Pubmed
      MsgBox, 4, The text you entered is %pubsource%
   IfMsgBox, No
	Return
   Send %pubsource% ; enter text in Reviewed Item field
   ; -------------------------------------------------------------------------------------------------------
   Send {TAB}
   Send {ENTER 2}
   ; ------------------------------------------------------------------------------------
   ; ----- The following code checks to see if update window has closed yet -----
   ; ------------------------------------------------------------------------------------
   SetTitleMatchMode,1
   WinWait, Changing Fields... ; wait until update window closes
   WinWaitClose ; wait until update window closes
   ; ------------------------------------------------------------------------------------
   Send {Enter}
; finished section 2 - entering origin of pub (pubmed) and date
}
; ------------------------------------------------------------------------------
; ------------------ copy Accession field to Label field ---------------------
; ------------------------------------------------------------------------------
SetTitleMatchMode,1 ; title must begin with String
IfWinExist,EndNote X9
{
   WinActivate
   Send !t ; send alt t to access the tools menu
   Send {c 2} ; send to c keystrokes to access the change submenu
   Send {ENTER} ; send enter key to choose menu
   Send +{TAB} ; access menu one above
   Send {Right} ; move right one tab
   Send {TAB} ; move to from field
   Send {a 4} ; press a 4x to choose accession number
   Send {Tab}
   Send {L} ; choose label field
   Send {TAB}
   Send {Down 2} ; choose replace entire field
   Send {TAB 2} ; two tabs if the former field is chosen
   Send {Down} ; choose to copy field
   Send {TAB} ; to get to next field
   Send {ENTER}
   Send {ENTER}
   ; ------------------------------------------------------------------------------------
   ; ----- The following code checks to see if update window has closed yet -----
   ; ------------------------------------------------------------------------------------
   SetTitleMatchMode,1
   WinWait, Copying Fields... ; wait until update window closes
   WinWaitClose ; wait until update window closes
   ; ----------------------------------------------------------------------------
   Send {Enter}
; finished section 3 - copying pmid to label
}
; ------------------------------------------------------------------------------
; ----------------- copy record number to call number --------------------
; ------------------------------------------------------------------------------
SetTitleMatchMode,1 ; title must begin with String
IfWinExist,EndNote X9
{
   WinActivate
   Send !t ; send alt t to access the tools menu
   Send {c 2} ; send to c keystrokes to access the change submenu
   Send {ENTER} ; send enter key to choose menu
   Send +{TAB} ; access menu one above
   Send {Right} ; move right one tab
   Send {TAB 4} ; go to move/copy selection
   Send {Down} ; ; choose to copy field instead of moving
   Send {TAB 4} ; move from copy field to from field
   Send {r 3} ; press r 3x to choose record number
   Send {Tab}
   Send {c 8} ; press c 8x to choose call number field
   Send {TAB}
   Send {Down 2} ; choose replace entire field
   Send {TAB 3} ; three tabs if the former field is chosen
   Send {ENTER 2}
   ; ------------------------------------------------------------------------------------
   ; ----- The following code checks to see if update window has closed yet -----
   ; ------------------------------------------------------------------------------------
   SetTitleMatchMode,1
   WinWait, Copying Fields... ; wait until update window closes
   WinWaitClose ; wait until update window closes
   ; ----------------------------------------------------------------------------
   Send {Enter}
; finished section 4 - copying record number to call number
}
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
; -------------                                                              -----------------
; ------------- Normalize the author IDs (custom 5 field) -----------------
; -------------                                                              -----------------
; ------------------------------------------------------------------------------
; ------------------------------------------------------------------------------
;
; ---------------------------------------------------------------
; --------- Replace https orcid.org /  Broken Link for safety in custom 5 -----------
; ---------------------------------------------------------------
   Send {Ctrl}+r ; send control + r to start replace dialog
   Send {TAB 6} ; send 6 tabs to select field menu
   Send {C 4} ; send c 4 times to select the custom 5 field
   Send {Tab 2} ; select the Find box
   Send https orcid.org /  Broken Link for safety ; send text to replace
   Send {Tab 5} ; tab to Change button
   Send {Enter} ; select change
   Sleep 5000 ; sleep 5 seconds
   Send {Enter} ; click ok
; ---------------------------------------------------------------
; --------- Replace http orcid.org /  Broken Link for safety in custom 5 -----------
; ---------------------------------------------------------------
   Send {Ctrl}+r ; send control + r to start replace dialog
   Send {TAB 6} ; send 6 tabs to select field menu
   Send {C 4} ; send c 4 times to select the custom 5 field
   Send {Tab 2} ; select the Find box
   Send http orcid.org /  Broken Link for safety ; send text to replace
   Send {Tab 5} ; tab to Change button
   Send {Enter} ; select change
   Sleep 5000 ; sleep 5 seconds
   Send {Enter} ; click ok
; finish section 5 - remove https orcid.org /  Broken Link for safety and http orcid.org from authorid   Broken Link for safety
; ---------------------------------------------------------------------------------------
; -------------------         Place all authorIDs on one line         --------------------
; ---------------------------------------------------------------------------------------
Sleep 1000 ; sleep 1 second
   Send {Ctrl}+r ; send control + r to start replace dialog
   Send {TAB 6} ; send 6 tabs to select field menu
   Send {C 4} ; send c 4 times to select the custom 5 field
   Send TAB 2} ; go to find field
   Send {SHIFT} {TAB} ; go back to special menu
   Send S ; select insert Special
   Send {DOWN 2} ; highlight carriage return
   Send {ENTER} ; select carriage return
   Send {TAB 3} ; goto replace with box
   Send {Comma} ; enter comma
   Send {{Space} ; enter space
   Send {TAB 2}; tab to replace
   Send {Enter} ; select replace
   Sleep 5000 ; sleep 5 seconds while checking for record matches
   Send {Enter} ; select okay to continue
   Send {Enter} ; select okay to continue
; finish section 6 - place all authorIDs on one line
; ---------------------------------------------------------------------------------------
; -------------------         Place all grant info  on one line         --------------------
; ---------------------------------------------------------------------------------------
Sleep 1000 ; sleep 1 second
   Send {Ctrl}+r ; send control + r to start replace dialog
   Send {TAB 6} ; send 6 tabs to select field menu
   Send {T 4} ; send T 6 times to select the translated title field
   Send TAB 2} ; go to find field
   Send {SHIFT} {TAB} ; go back to special menu
   Send S ; select insert Special
   Send {DOWN 2} ; highlight carriage return
   Send {ENTER} ; select carriage return
   Send {TAB 3} ; goto replace with box
   Send {Comma} ; enter comma
   Send {Space} ; enter space
   Send {TAB 2}; tab to replace
   Send {Enter} ; select replace
   Sleep 5000 ; sleep 5 seconds while checking for record matches
   Send {Enter} ; select okay to continue
   Send {Enter} ; select okay to continue
; finish section 7 - place all grant info on one line
: need to Manually bold Author names in author field
; need to manually enter program information
; need to manually mark for cancer relevance
; need to enter journal impact factor in caption field
MsgBox, 4, After finishing this script the following items still need to be done.  Do you wish to continue? 'n'nManually bold Author names in author field'nManually enter program information'nManually mark for cancer relevance'nEnter journal impact factor in caption field
IfMsgBox, No
	Return

Return to “Ask for Help (v1)”