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?
Why won't my script run correctly?
- divanebaba
- Posts: 804
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: Why won't my script run correctly?
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.
Addbefore 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.
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
More reliable would/could be the WinMenuSelectItem command, which is most time able to choose menu items of desired foreign windows.
Re: Why won't my script run correctly?
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 (21.33 KiB) Viewed 1000 times
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Why won't my script run correctly?
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.
This will start Acrobat, make it visible, and do a scan using the Preset 1.
FG
Code: Select all
App := ComObjCreate("AcroExch.App")
App.Show()
App.MenuItemExecute("ScanPreset1")
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
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
Re: Why won't my script run correctly?
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.
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.
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Why won't my script run correctly?
Well it is not like I threw you to the wolves with just an off hand comment to use COM.Garrett wrote:The suggestion to use COM is intriguing, but I'm afraid it's way beyond my ability to write AutoHotkey scripts!
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
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
Re: Why won't my script run correctly?
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.
;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.
Re: Why won't my script run correctly?
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.
- FanaticGuru
- Posts: 1906
- Joined: 30 Sep 2013, 22:25
Re: Why won't my script run correctly?
Hmm... that exact code, copy and pasted, works for me when I push Alt+S.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.
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")
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
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
Re: Why won't my script run correctly?
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)?
Re: Why won't my script run correctly?
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!
Who is online
Users browsing this forum: No registered users and 137 guests