AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

turn command-line arg into file dialog input (fix MDI app)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
42td



Joined: 21 Mar 2008
Posts: 2

PostPosted: Fri Mar 21, 2008 6:14 pm    Post subject: turn command-line arg into file dialog input (fix MDI app) Reply with quote

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. Wink
Back to top
View user's profile Send private message
supergrass



Joined: 21 Feb 2007
Posts: 29
Location: Australia

PostPosted: Mon May 19, 2008 8:00 am    Post subject: setting up file associations Reply with quote

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 Embarassed
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Mon May 19, 2008 10:26 am    Post subject: Reply with quote

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
Back to top
supergrass



Joined: 21 Feb 2007
Posts: 29
Location: Australia

PostPosted: Wed May 21, 2008 4:00 am    Post subject: Reply with quote

Sad 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.
Back to top
View user's profile Send private message
n-l-i-d
Guest





PostPosted: Wed May 21, 2008 12:07 pm    Post subject: Reply with quote

* 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
Back to top
supergrass



Joined: 21 Feb 2007
Posts: 29
Location: Australia

PostPosted: Thu May 22, 2008 5:29 am    Post subject: could not use ahk file in the file associations Reply with quote

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.
Back to top
View user's profile Send private message
42td



Joined: 21 Mar 2008
Posts: 2

PostPosted: Sun Jun 08, 2008 7:07 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group