Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Open pdf with non-default program


  • Please log in to reply
5 replies to this topic
MChristensen1988
  • Members
  • 8 posts
  • Last active: Feb 25 2016 01:12 PM
  • Joined: 20 Jul 2015

Hey!

 

I'm using Adobe Reader and Bluebeam Revu to view pdf files.

 

My default program is Adobe, but I would like to open pdf files in Revu when I ctrl+double click on them.

This however has proven beyond my ahk capabilities.

 

So I figured I would do it the "easy" way and just use the MouseMove function to right click and "open with".

So far I have this script:

^~LButton::
If (A_TimeSincePriorHotkey<400) and (A_TimeSincePriorHotkey<>-1)
Click Right
MouseGetPos, PosX, PosY ; Save current mouse-curser position
BlockInput On ; Disables manual mouse movement during this function
MouseMove, 10, 100, 50, R ;
MouseMove, 100, 0, 50, R
Click ; Left click
MouseMove, %PosX%, %PosY%, 0 ; Move mouse-cursor back to original position
BlockInput Off ; Enables manual mouse movement again
Return
 
But for some reason, when I use "MouseMove, 10, 100, 50, R ;" it doesn't run any of the code above. Why is that and is there a way to fix it?
 
Also, as I realize this is not the smartest way of doing it, is there a more practical way of telling it to run the file in a different program when i ctrl+double click?


kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

You could try using this script to get the path of the .pdf: Get paths of selected items in an explorer window

sel := Explorer_GetSelected()

 

Then use run to open the pdf.

Run, "C:\Somefolder\Revu.exe" "%sel%"

 

Note: Change "C:\Somefolder\Revu.ex" to the actual path to your .exe. Also, if you have multiple items selected, "sel" will contain the paths of all the items  (one on each line).



MChristensen1988
  • Members
  • 8 posts
  • Last active: Feb 25 2016 01:12 PM
  • Joined: 20 Jul 2015

It seems to work, at least somewhat work.

However, the peace of code I've ended up with is:

 

^~LButton::
If (A_TimeSincePriorHotkey<400) and (A_TimeSincePriorHotkey<>-1)
sel := Explorer_GetSelected()
Run, "C:\Program Files\Bluebeam Software\Bluebeam Revu\Revu\Revu.exe" "%sel%"
return

But when I double click it opens the actual pdf file in Adobe, and it opens the program Revu, but not the pdf file.

 

If I however, exchange the two first lines of code, so it looks like this:

^MButton::
;If (A_TimeSincePriorHotkey<400) and (A_TimeSincePriorHotkey<>-1)
sel := Explorer_GetSelected()
Run, "C:\Program Files\Bluebeam Software\Bluebeam Revu\Revu\Revu.exe" "%sel%"
return
Everything works perfectly. It doesn't really matter whether I use Mbutton or doubleclick Lbutton, I would just like to know why the one works and the other doesn't?


Grant
  • Members
  • 14 posts
  • Last active: Nov 13 2015 10:03 AM
  • Joined: 03 Feb 2010

 

^~LButton::
If (A_TimeSincePriorHotkey<400) and (A_TimeSincePriorHotkey<>-1)
sel := Explorer_GetSelected()
Run, "C:\Program Files\Bluebeam Software\Bluebeam Revu\Revu\Revu.exe" "%sel%"
return

But when I double click it opens the actual pdf file in Adobe, and it opens the program Revu, but not the pdf file.

 

 

 

The "~" sends your left click and might be un-selecting your file between your 2 clicks resulting in:

 

1) a double click on the file opening it

and

2) a void from "sel := Explorer_GetSelected() " because the file is no longer selected

followed by

3) an execution of "Run, "C:\Program Files\Bluebeam Software\Bluebeam Revu\Revu\Revu.exe" "%sel%" " where %sel% is void.

 

Try adding a msgbox to test this.



kon
  • Members
  • 1652 posts
  • Last active:
  • Joined: 04 Mar 2013

I tested it and Grant is right. ~ lets the Ctrl+Click "pass through" instead of being blocked by the script, which has the effect of de-selecting the file.

 

Maybe something like this if you want to use Ctrl+Click for the hotkey:

$^LButton::
if (A_PriorHotkey = "$^LButton" && A_TimeSincePriorHotkey < 400) {
    sel := Explorer_GetSelected()
    ;MsgBox, % Sel
    Run, "C:\Program Files\Bluebeam Software\Bluebeam Revu\Revu\Revu.exe" "%sel%"
}
else
    Send, {LButton}
return

Also, adding braces around the body of the if is important, otherwise the Run command will be executed every time you press the hotkey (not just for double clicks).



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I would guess that Send, {Blind}{LButton} would be more appropriate. Without {Blind} or ^ you won't be able to Ctrl+Click to select/deselect items.

Explorer_Get() uses window.document.SelectedItems. I suppose that window.document.FocusedItem would return the item you clicked even if you just deselected it.

I would use a different method: Change PDF files to open with a script of your making. The script would check GetKeyState("Ctrl") to determine which program to launch.