Script Clean Up

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bones23
Posts: 5
Joined: 29 Sep 2017, 04:00
Location: Gloucester, UK

Script Clean Up

19 Oct 2017, 06:11

Hi All,

Apologies if I have posted in the incorrect forum. I am a (mostly) self taught Vba coder and I have a basic understanding of code writing, recently my Manager has introduced me to the world of AHK to perform a function that at present I am unable to achieve via vba and I have written a AHK script which mostly achieves my objective but it's scrappy and could do with some tidying up. So I decided to turn to the Experts :)

Essentially I have a series of reports which lists hyperlinks in a spreadsheet (could be 500+) to documents based on a SharePoint site which we are regularly asked to print, to achieve this I have come up with the below, I have tried to REM each line so you know can follow what I am trying to achieve:

SendMode Event ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetKeyDelay, 1000
SendMode, Input

#space::

Run, Iexplore.exe, ,max ; Open new IE window
sleep,2000 ; 2Second gap to allow PC to catch up
; Retrieve the ID/HWND of the active window
id := WinExist("A")
Sleep, 2000 ; 2 second
send,{Ctrl Down}{T} ;Open New Tab in IE
send,{Ctrl Up} ; Unpress Ctrl
send,{Alt down}{F} ; Run from IE (Close all TABS FIRST) - Selects File Menu
send,{Alt Up} ; Unpresses Alt
send,{O} ; Opens the Open menu
send,{Raw} http://LinkToHyperLink/LinkToHyperLink/ ... cument.tif; Enters link to sharepoint, gap left to try to prevent characters being missed from start of hyperlink string
send,{Enter} ;Press Enter
send,{Enter} ;Press Enter
Sleep, 5000 ; 5 second gap to allow image to open
; Retrieve the ID/HWND of the active window
id := WinExist("A")
Send,{Alt down}{P} ; Selects Print Menu in Photo Viewer
send,{Ctrl down}{P} ; Selects Print from the Print Menu
send,{Ctrl Up} ; Unpresses the Ctrl key
; Retrieve the ID/HWND of the active window
id := WinExist("A")
Sleep, 2000 ; 2 second gap to allow print to generate
send,{Alt Down}{P} ; Confirms Print in the Print menu
Sleep, 8000 ; 8 second gap to allow image to send to printer
send,{Alt Down}{F4} ; Closes Windows Photo View
send,{Alt Up} ; Unpresses Alt
send,{Alt Down}{F4} ;Closes current IE Window
send,{Alt Up} ; Unpresses Alt
sleep,1000 ; 1 Second gap to allow system to catch up

As I say I am a complete Noob to AHK so although my code does work, It has a few issues (apart from being very long).

1) When entering the hyperlink address it occasionally misses the initial characters - I have read using {Raw} and adding additional spaces to the string should prevent this but occasionally the initial characters are still missed
2) Sometimes although the Hyperlink exists on the spreadsheet the document hasn't actually been uploaded to the SharePoint yet, this is problematic as the code doesn't detect the missing document and continues to run the code as it would if it was there. Is there a way to detect and prevent this?
3) Not so much a problem, more curiosity. The code seems to contain a lot of lines, in vba I would try to condense my code to allow it to process quickly, AHK I wouldn't know where to start... If anyone could offer any guidance that would be greatly appreciated

Anyway thanks for accepting me into your Community and I look forward to progressing my AHK knowledge :)
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Script Clean Up

19 Oct 2017, 06:57

Do you have to open the image within IE/Sharepoint by any means?
Bc, you if know the link already you should be able to hand it over to photoviewer.dll directly (end of guessing).
Bones23
Posts: 5
Joined: 29 Sep 2017, 04:00
Location: Gloucester, UK

Re: Script Clean Up

19 Oct 2017, 10:03

Hi BoBo,

Thanks for replying, I'm not sure I totally understand your question, however if you are asking if the image needs to be opened before printing I would prefer if it actually didn't. So far I have found no way to be able to be able to print the image without opening it.

The link unfortunately is a direct link to the file on the SharePoint which will open the image once clicked.

Hope this helps :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 387 guests