Why won't my script run correctly?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Garrett
Posts: 8
Joined: 20 Sep 2017, 11:12

Why won't my script run correctly?

20 Sep 2017, 11:29

I'm a novice user of AutoHotkey but run a number of simple scripts successfully. I'm trying to write one for Adobe Acrobat that will start scanning a document in my scanner. Here my script:

;Starts scanning a document (when Acrobat is running)
;
#SingleInstance force
^!s::
Send !frs{TAB 4}{Enter}
return

Script runs correctly up to the {TAB 4} but stops there. If I manually hit the tab key four times and then enter, Acrobat starts the scan. So why doesn't my script do it?
User avatar
divanebaba
Posts: 804
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Why won't my script run correctly?

20 Sep 2017, 12:51

Hi.
I don't really know, why the TAB commands not respond, but I think, that you are opening menu items of the acrobat window.
Try to insert a little break, to give the menu items enough time to open completely.
Add

Code: Select all

sleep 300
before you send the tabs.
More reliable would/could be the WinMenuSelectItem command, which is most time able to choose menu items of desired foreign windows.
Garrett
Posts: 8
Joined: 20 Sep 2017, 11:12

Re: Why won't my script run correctly?

22 Sep 2017, 10:51

The "sleep 300" line doesn't have any effect. The screen in question isn't standard windows menu. I'll try to attach a screenshot. The last item is a box labeled SCAN for me to click. Is there a way I can get AutoHotkey to click it?
Attachments
Acrobat Screenshot.png
Acrobat Screenshot.png (21.33 KiB) Viewed 1000 times
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Why won't my script run correctly?

22 Sep 2017, 11:24

If you want to get fancy, you can try it through COM and skip all the navigating through the menus and tabbing to the right options.

Code: Select all

App := ComObjCreate("AcroExch.App")
App.Show()
App.MenuItemExecute("ScanPreset1")
This will start Acrobat, make it visible, and do a scan using the Preset 1.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Garrett
Posts: 8
Joined: 20 Sep 2017, 11:12

Re: Why won't my script run correctly?

23 Sep 2017, 10:03

The suggestion to use COM is intriguing, but I'm afraid it's way beyond my ability to write AutoHotkey scripts!

I've tried using Click x, y but that doesn't work either. Once it reaches the Acrobat page with the Scan options, it always just stops there. I can't seem to make it go ahead and click on the SCAN button to start the scanner.
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Why won't my script run correctly?

25 Sep 2017, 12:57

Garrett wrote:The suggestion to use COM is intriguing, but I'm afraid it's way beyond my ability to write AutoHotkey scripts!
Well it is not like I threw you to the wolves with just an off hand comment to use COM.

I gave you the exact three lines of code that would cause Acrobat to do a scan. Fully understanding code should not be an inhibitor to using what works.

In the end almost everyone is using code they do not fully understand.

People use snippets of code, libraries, functions, classes, etc. written by others to make AHK code...

AHK code is just a collection of other peoples work that few understand to make it easier to do things in C++...

C++ is just a collection of other peoples work to make working with Assembly language easier...

And of course Assembly is just other peoples work to make Machine language easier to work with...

Machine language is just processor instructions created by alien technology to allow us to communicate with machines from the future.

At least that is my understanding, all the details get a little fuzzy.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Garrett
Posts: 8
Joined: 20 Sep 2017, 11:12

Re: Why won't my script run correctly?

28 Sep 2017, 11:11

FanaticGuru clearly doesn't suffer beginners gladly. But I'm thick-skinned and would like to pursue the issue. Here's how I've tried to incorporate his suggested code:

;Starts scanning a document (when Acrobat is NOT running)
#SingleInstance force
!s::
App := ComObjCreate("AcroExch.App")
App.Show()
App.MenuItemExecute("ScanPreset1")
return

But it doesn't work, so evidently I'm doing something wrong.
User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Why won't my script run correctly?

28 Sep 2017, 13:16

Not so clearly. In fact, you took FanaticGuru's comments exactly the wrong way. Rather than making a quick dismissive remark, he took his time to give you context for what he was saying because you are a beginner. He was saying the opposite of what you think he said. He is saying that even savvy programmers use code they don't really understand (or need to understand), so it's common practice to use code you don't understand and encouraged you to do the same.
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Why won't my script run correctly?

28 Sep 2017, 14:50

Garrett wrote:;Starts scanning a document (when Acrobat is NOT running)
#SingleInstance force
!s::
App := ComObjCreate("AcroExch.App")
App.Show()
App.MenuItemExecute("ScanPreset1")
return

But it doesn't work, so evidently I'm doing something wrong.
Hmm... that exact code, copy and pasted, works for me when I push Alt+S.

You have to have 'Adobe Acrobat' installed on your computer. The real cost-money 'Adobe Acrobat' but your screenshot shows Adobe Acrobat Pro 2017 so that should not be the problem.

I am using an older version, 'Adobe Acrobat XI Pro', but that should not be a problem either. Could be, maybe.

Does Acrobat start up at all?

If it does then maybe "ScanPreset1" is no longer a valid MenuItem in the newest version.

You can cause Acrobat to display the names of most all MenuItems by doing this in Acrobat.

In order to run a JavaScript in Acrobat, it's sufficient to open the Console (Ctrl+J), paste the code into it, select it (must highlight the code) and then press the Enter key at the bottom-right of the keyboard (has to be this Enter key).

Here's the JaveScript code to list all of the available menu items to the console in Acrobat:

Code: Select all

var menuItems = app.listMenuItems()
for( var i in menuItems)
console.println(menuItems+ + "\n")
I admit it is now getting a little complicated and that big ugly list of MenuItem names is not very user friendly. But maybe you or others will find it helpful for using Acrobat MenuItems through AHK COM.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
Garrett
Posts: 8
Joined: 20 Sep 2017, 11:12

Re: Why won't my script run correctly?

05 Oct 2017, 15:35

Yes, the script does start Acrobat, but it leaves a blank screen showing. Could the problem be that I'm running Acrobat 2017 (not Acrobat XI)?
Garrett
Posts: 8
Joined: 20 Sep 2017, 11:12

Re: Why won't my script run correctly?

05 Oct 2017, 15:39

I got my original script (the one that requires me first to run Acrobat) to run correction by using MouseClick. Thanks to those that helped!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 137 guests