Passing a file to a compiled script?
Moderators: JRL, Dorian (MJT support)
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Passing a file to a compiled script?
I have looked at all the topics and they don't seem to apply to what I want (I'm not even sure if it's possible - although I get the feeling it probably is).
As an example (this is part of a pretty massive script):
Say I have a script that when compiled is called parameter_test.exe
First all I want to do is get the name of a file dragged onto that script.
So for example I drop the image:
C:\Users\Phil\Downloads\test.jpg
On to the parameter_test.exe
The script now opens and I (for example) want it to simply display a message with the image name. C:\Users\Phil\Downloads\test.jpg
(The actual script is not that simple but this is the easiest way I can think of to explain what I need).
I will also then need to test if the variable that has been defined by opening the exe with a drag and drop has already been assigned or not. So that if the exe is started by a normal double click a different procedure will happen.
I hope this makes sense and I hope someone can offer some assistance.
So can someone show the code (if it is possible) required to show a message of the filename that has been dragged onto a compiled macro exe file.
And if that is possible - the code required to check if that variable has been assigned (although I suspect this is just a permutation of if>exists).
If I can get this working I will post the full script as it is quite useful and shows off some of MS great features.
Thanks.
As an example (this is part of a pretty massive script):
Say I have a script that when compiled is called parameter_test.exe
First all I want to do is get the name of a file dragged onto that script.
So for example I drop the image:
C:\Users\Phil\Downloads\test.jpg
On to the parameter_test.exe
The script now opens and I (for example) want it to simply display a message with the image name. C:\Users\Phil\Downloads\test.jpg
(The actual script is not that simple but this is the easiest way I can think of to explain what I need).
I will also then need to test if the variable that has been defined by opening the exe with a drag and drop has already been assigned or not. So that if the exe is started by a normal double click a different procedure will happen.
I hope this makes sense and I hope someone can offer some assistance.
So can someone show the code (if it is possible) required to show a message of the filename that has been dragged onto a compiled macro exe file.
And if that is possible - the code required to check if that variable has been assigned (although I suspect this is just a permutation of if>exists).
If I can get this working I will post the full script as it is quite useful and shows off some of MS great features.
Thanks.
Phil Pendlebury - Linktree
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
'fraid that's not possible. An exe has no drag-drop support like that.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Ahh Ok Marcus thank you. I thought I could see people doing something similar but I guess I misunderstood:-)
I'll post the script up anyway then shortly.
I'll post the script up anyway then shortly.
Phil Pendlebury - Linktree
Sorry but I disagree.
Hi Phil,
The secret to this is the system variable command_line
Compile a short script with one line
MDL>%command_line%
Drop your jpg file on the executable and look at the result.
It will look some thing Like:
a) recognize that a file was dropped on the executable
b) separate the filename from the command_line variable
c) deal with the passed file
a) What I do at the start of the script is separate command_line by "quote space quote" ( " " ) then look to see if I have two variables. If there are two then I have a passed parameter.
b) already done in a)
c) that's up to you.
Hope this is helpful.
Hi Phil,
The secret to this is the system variable command_line
Compile a short script with one line
MDL>%command_line%
Drop your jpg file on the executable and look at the result.
It will look some thing Like:
So within your script you need to:MDL> wrote: "C:\Documents and Settings\dickl\Desktop\Passing parameters.exe" "C:\Documents and Settings\dickl\Desktop\sample.JPG"
a) recognize that a file was dropped on the executable
b) separate the filename from the command_line variable
c) deal with the passed file
a) What I do at the start of the script is separate command_line by "quote space quote" ( " " ) then look to see if I have two variables. If there are two then I have a passed parameter.
b) already done in a)
c) that's up to you.
Hope this is helpful.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Doh - of course! I had tried it with MACRO_PARMS. Yes, JRL is right, it's inherent in Windows. When you drag something to the exe it is as if the filename was passed on the command line. So if you look at COMMAND_LINE you will see it in there and can parse it out. Sorry.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Here's a useful example. Compile the following then drop any file on the new executable's icon. The dropped file's name will be placed on the clipboard.
HERE is a precompiled executable called "Acquire File Name.exe" for anyone who wants it.
Otherwise here is the script to compile yourself.
HERE is a precompiled executable called "Acquire File Name.exe" for anyone who wants it.
Otherwise here is the script to compile yourself.
Code: Select all
Separate>command_line," ",var
If>var_count=2
StringReplace>var_2,",,var_2
PutClipBoard>%var_2%
MDL>var_2
Else
Let>CommandLine=%Command_Line%
StringReplace>commandline,",,commandline
PutClipBoard>%commandline%
MDL>Commandline
EndIf
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Thanks guys. This works for me:
For some reason the " " in JRL's separate line was throwing me off.

Code: Select all
Separate>command_line," ,cmd_var
IF>cmd_var_2=
Mdl>NO STRING
// Do stuff you would do if app was started normally
ELSE
Mdl>cmd_var_2
// cmd_var_2 will be the file name
ENDIF
For some reason the " " in JRL's separate line was throwing me off.

Phil Pendlebury - Linktree
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
The finished section inserted into the script before the dialog and the ini file etc.
Not as elegant as JRL's but it works for me. 
Code: Select all
Let>def_file=
Separate>command_line," ,cmd_var
IF>cmd_var_2=
// DO NOTHING but leave this here just in case needed later
ELSE
Let>def_file=cmd_var_2
StringReplace>def_file,",,def_file
ENDIF

Phil Pendlebury - Linktree
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Hi JRL.
It didn't seem to work constantly.
But I have a habit of doing things my own way - so that I understand them.
As you can see I still had to strip the " after inserting into my script. So that's an odd one.
I have to run now but will look at this later.
Your help was awesome as usual thank you both.

It didn't seem to work constantly.
But I have a habit of doing things my own way - so that I understand them.
As you can see I still had to strip the " after inserting into my script. So that's an odd one.
I have to run now but will look at this later.
Your help was awesome as usual thank you both.

Phil Pendlebury - Linktree
I rewrote this to be able to process multiple files dragged onto the executable icon. Its a slightly different method to acquire the file name(s). I think its a little easier to follow. To use this just plug into the Process subroutine, the activity you want to perform on each file.
Code: Select all
LowerCase>Command_Line,Command_Line
LowerCase>script_file,script_file
StringReplace>Command_Line,",,Command_line
StringReplace>Command_Line,Script_File,,File[s]ToProcess
MidStr>File[s]ToProcess,1,3,drive
Separate>File[s]ToProcess,drive,file
Let>kk=1
Repeat>kk
Add>kk,1
Let>value=file_%kk%
IfFileExists>value
GoSub>Process
EndIf
Until>kk=File_count
SRT>Process
MDL>File %kk% = %value%
END>Process