AutoHotkey Community

It is currently May 27th, 2012, 6:05 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: March 21st, 2008, 6:14 pm 
Offline

Joined: March 21st, 2008, 5:42 pm
Posts: 2
Say you have an MDI application which behaves well when the file open dialog is used and badly (opens a new window) when you start it a second time with a file argument. (The latter, of course, is what usually happens if it is the default app for the file type and you open a document in a file manager.)

The following hack fixes this behavior by simulating file open dialog input:

Code:
; Opens %1% in existing F.x.. Reader window or starts a new one
; *.pdf file association example: "C:\Program files\AutoHotkey\AutoHotkey.exe" "d:\ahk\fx_open.ahk" "%1"

SetTitleMatchMode RegEx

if (WinExist("- F.x.. Reader [0-9. ]*-") or WinExist("^F.x.. Reader [0-9. ]*$"))
{
   WinActivate
   Send ^o
   Sleep 200
   SendRaw %1%
   Send {enter}
}
else
{
   Run "c:\\program files\\fxreader\\fxreader.exe" "%1%"
}


Things to customize according to your needs:
  • window title patterns (WinExist parameters)
  • command-line to run the app
  • maybe the key stroke CTRL+o to open the dialog
  • maybe the pause after CTRL+o

You can then set up a file association with autohotkey.exe "AHK_script" "%1" as mentioned in the code.

I've obfuscated the application name a little since i'm not sure whether its license permits this. Maybe someone is brave enough to post a guess so that this topic can be found easier. ;-)


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 19th, 2008, 8:00 am 
Offline

Joined: February 21st, 2007, 5:52 am
Posts: 51
Location: Australia
I too hate the multiple instance of pdf readers when files are opened from an explorer window.

Quote:
"C:\Program files\AutoHotkey\AutoHotkey.exe" "d:\ahk\fx_open.ahk" "%1"


Are all the " to be used literally in the file association? I tried a couple of combinations but no cigar :oops:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2008, 10:26 am 
Passing Command Line Parameters to a Script

Quote:
The format is:

AutoHotkey.exe [Switches] [Script Filename] [Script Parameters]


Code:
; "C:\Program files\AutoHotkey\AutoHotkey.exe" "d:\ahk\fx_open.ahk" "%1"

Run, "C:\Program files\AutoHotkey\AutoHotkey.exe" "d:\ahk\fx_open.ahk" "e:\path\to\your\pdf\file.pdf"


The %1 (should be %1%) is the variable containing the first "input", make sure you feed it something :wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2008, 4:00 am 
Offline

Joined: February 21st, 2007, 5:52 am
Posts: 51
Location: Australia
:( maybe I am a little slow, even with the "%1%", I go to Tools>Folder Options>File Types and Click the Change Button, then Browse and enter the full path ie C:\Program Files\AutoHotkey\AutoHotkey.exe" "c:\myfolder\myfile.ahk" "%1%" Directly into the file name box.

I get the error:
Quote:
C:\Program files\AutoHotkey\AutoHotkey.exe" "c:\C:\Program files\AutoHotkey\scripts\pdfopener.ahk" "%1%"
The above file name is invalid.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2008, 12:07 pm 
* Windows:

1. Explorer menu: Tools -> Folder Options -> File Types
2. Select file type, press "Advanced"
3. Select "Open" and press "Edit"
4. Insert your command line into the field "Application used to perform action"

Windows uses %1 (%2, %3 etcet.) to denote the dropped/activated file-path(s) as variable(s).

If a command line contains paths with spaces, they need to be enclosed in double-quotes.

Replace everything including the <> in the following examples with your values:

Quote:
<short path to your application> <short part to the file to feed the application>

<path without spaces to your application> <path without spaces to the file to feed the application>

"<path with spaces to your application>" "<path with spaces to the file to feed the application>"

"<path with spaces to your application>" /switch "<path with spaces to the file to feed the application>"

"<path with spaces to your application>" <anything>

"<path with spaces to your application>" /switch "%1"


* AutoHotkey:

Passing Command Line Parameters to a Script, the Run command

AutoHotkey uses %1% (%2%, %3% etcet.) to denote the dropped/activated file-path(s) as variable(s).

If a command line contains paths with spaces, they are preferred to be enclosed in double-quotes (but it is not always necessary). Don't forget to escape the comma's.

---

So, when in Windows:

Quote:
C:\Program files\AutoHotkey\AutoHotkey.exe" "c:\C:\Program files\AutoHotkey\scripts\pdfopener.ahk" "%1"


try this instead

Quote:
"C:\Program files\AutoHotkey\AutoHotkey.exe" "C:\Program Files\AutoHotkey\scripts\pdfopener.ahk" "%1"


or this

Quote:
"C:\Program files\AutoHotkey\AutoHotkey.exe" ""C:\Program Files\AutoHotkey\scripts\pdfopener.ahk" "%1""


if you compile your pdfopener script, you could use:

Quote:
"C:\Program Files\AutoHotkey\scripts\pdfopener.exe" "%1"


HTH


Report this post
Top
  
Reply with quote  
PostPosted: May 22nd, 2008, 5:29 am 
Offline

Joined: February 21st, 2007, 5:52 am
Posts: 51
Location: Australia
Thanks n-l-i-d.

I did as you said except I had to convert the script into an exe for it to be accepted - maybe because my ahk association is not registered correctly?

The advanced button was not available at first because I had a custom association already - running pdf 5 and reader 8 on same machine.

I made a few adjustments to the script, using sendinput and winwait - in preference to send and sleep - so far so good.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 8th, 2008, 7:07 pm 
Offline

Joined: March 21st, 2008, 5:42 pm
Posts: 2
Sorry for the late reply - i've been on vacation. Now all which is left to be answered is
Quote:
I had to convert the script into an exe for it to be accepted - maybe because my ahk association is not registered correctly?


The ahk association shouldn't matter here. With the correct *.pdf association Windows knows that it should start Autohotkey with the AHK script and file arg, and Autohotkey knows what to do with that regardless of the *.ahk association.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: example using acrobat
PostPosted: October 14th, 2010, 10:54 pm 
Offline

Joined: February 21st, 2007, 5:52 am
Posts: 51
Location: Australia
We use an old version of acrobat at work, but it still supports most of the pdfs I receive. Just resurrected this after IT deployed a new one that is not as good for reviewing and rotating drawings.

Code:
; Opens %1% in existing F.x.. Reader window or starts a new one
; *.pdf file association example: "C:\Program files\AutoHotkey\AutoHotkey.exe" "d:\ahk\fx_open.ahk" "%1"

;SetTitleMatchMode RegEx

if (WinExist(Acrobat))
{
   WinActivate
   SendInput ^o
   WinWait, Acrobat
   SendRaw %1%
   SendInput {Enter}
}
else
{
   Run "C:\\Program Files\\Adobe\\Acrobat 5.0\\Acrobat\\Acrobat.exe" "%1%"
}


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 14th, 2010, 11:38 pm 
42td wrote:
...which behaves well when the file open dialog is used and badly (opens a new window) when you start it a second time with a file argument.

...lol...I actually have the opposite problem...& I would reverse your "well" & "badly" terms, I consider it bad to open in an existing window...I don't like window-cannibals.

Acrobat will always open PDFs in the "same window" or "same process"...I want all my PDFs in their own window & own process, for which I need to used Acrobats /n command line param.

But I do agree that ALL programs need...
  • a default in Preferences for what to do (new window/tab/process)
  • a command line param for new window/process always
  • a command line param to open in an existing window, if possible


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Exabot [Bot], Google [Bot], Google Feedfetcher, JamixZol, Yahoo [Bot] and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group