General :  K-Meleon Forum
General discussion about K-Meleon. 
[Solved] How to launch external app in KM?
Posted by: foliator
Date: April 24, 2016 01:59AM

I'm trying to create a macro that will open one of my desktop apps from within KM. I've tried the exec command, but so far, the only command line that works is exec("explorer.exe");

Other EXEs don't open, even if I provide the exact path for them. What's especially important here, however, is that I need to launch the shortcut to the app, not the executable itself, because the app depends on the properties of the shortcut to run properly.

In Windows, the path to the shortcut would look like this:
C:\Users\(my_username)\Documents\Apps\MemPad.lnk

Again in Windows, if I specify MemPad.exe instead, the app will start up, but it will look for a data file in the same folder as the app, which is not where I store it. I tried using that command line anyway in my macro, but there was no response at all.

Any ideas?

Update: I changed the backslashes in the command to forward slashes and finally got the app to come up, but only the executable file itself. The shortcut (MemPad.lnk) wouldn't open. Then I created a batch file that first changes to the data folder, then starts MemPad.exe through its full path to the app folder. It worked. For some reason, the exec command will open batch files, but what a workaround: A macro calling a batch file! Think I could get the macro to change directories on its own?

-----

Using KM 75.0 on Windows 7 (x86)

My personal Website. No ads, no scripts, no cookies -- no kidding!
http://gbusch.altervista.org



Edited 2 time(s). Last edit at 04/24/2016 08:21AM by foliator.

Options: ReplyQuote
Re: How to launch external app in KM?
Posted by: siria
Date: April 24, 2016 03:03AM

Hmm, no idea how to get lnk-links working...
But this page says it's also possible to use a commandline for the data folder, provided it ends with a backslash:
http://www.portablefreeware.com/forums/viewtopic.php?p=66617
Example: C:\Path\Mempad.exe C:\DataFolder\

In a macro that would translate to:
exec("C:\\Path\\Mempad.exe C:\\DataFolder\\");
Make sure all single backslashes in a path are double, otherwise single ones are escape signs for the following character.

If the path contains blanks, it's probably necessary to include quotes with escape signs, but just a guess, have not tested:
exec("\"C:\\P a t h\\Mempad.exe\" \"C:\\D a t a Folder\\\"");

Options: ReplyQuote
Re: How to launch external app in KM?
Posted by: foliator
Date: April 24, 2016 03:24AM

Ha! Thanks, siria, now I know why my backslashes didn't work. At any rate, the forward slashes did, as you'll now see in my previous message. Next I'll try and pass a parameter to MemPad the way you've pointed out. Maybe that will solve the problem; I'm crossing my fingers!

Hmmm ... kind of hard to type with my fingers crossed. grinning smiley

-----

Using KM 75.0 on Windows 7 (x86)

My personal Website. No ads, no scripts, no cookies -- no kidding!
http://gbusch.altervista.org

Options: ReplyQuote
[Solved] Re: How to launch external app in KM?
Posted by: foliator
Date: April 24, 2016 03:29AM

@siria: Yes, that fixed it; now I can throw away my batch file! Thanks again!

-----

Using KM 75.0 on Windows 7 (x86)

My personal Website. No ads, no scripts, no cookies -- no kidding!
http://gbusch.altervista.org



Edited 1 time(s). Last edit at 04/24/2016 03:30AM by foliator.

Options: ReplyQuote
Re: How to launch external app in KM?
Posted by: siria
Date: April 24, 2016 03:46AM

Thanks, glad that once in a while something actually works smiling smiley

Quote
foliator
I changed the backslashes in the command to forward slashes and finally got the app to come up

Huh?! Forward / ? surprised smiley Nice discovery!

Options: ReplyQuote
Re: How to launch external app in KM?
Posted by: foliator
Date: April 24, 2016 03:59AM

What gave me the idea for forward slashes was their use in URLs, at least in Mozilla-based browsers. As far as I know, only Internet Explorer recognizes backslashes in URLs. That's not surprising, since IE is integrated with Windows, but it's also not standard practice in browsers. I guess the use of forward slashes is actually a Unix thing.

PS: Just to clarify what I've done, I've only replaced the backslashes inside the actual path names - in fact, I used single forward slashes, not double ones - but I've kept the other backslashes in your macro command. Works fine (although the syntax looks kind of weird)!

-----

Using KM 75.0 on Windows 7 (x86)

My personal Website. No ads, no scripts, no cookies -- no kidding!
http://gbusch.altervista.org



Edited 2 time(s). Last edit at 04/24/2016 06:08AM by foliator.

Options: ReplyQuote
Re: How to launch external app in KM?
Posted by: guenter
Date: April 25, 2016 01:51AM

Can You post the full solution?

Options: ReplyQuote
Re: How to launch external app in KM?
Posted by: foliator
Date: April 25, 2016 06:03AM

Quote
guenter
Can You post the full solution?

Here it is, with only my user name masked:
MemPad{
exec("\"C:/Users/(username)/Documents/Apps/Mempad.exe\" \"C:/Users/(username)/Documents/Personal/Organizer.pad\"");
}
I formatted that as code, otherwise text wrapping would have obscured a space in the command. That long line extends beyond the table here, and in fact way beyond the width of my screen! surprised smiley

Since my last post I finally got the .pad file to open by association using some registry tricks, so I'm going to see if I can shorten the macro by just calling Organizer.pad.

Yes, that worked, but I had to add the .pad filetype to mimetypes.rdf and then choose to open them by default.

So this made a much simpler macro possible:

MemPad{
open("file://C:/Users/(username)/Documents/Personal/Organizer.pad");
}

At least I've learned something about handling external apps. grinning smiley

-----

Using KM 75.0 on Windows 7 (x86)

My personal Website. No ads, no scripts, no cookies -- no kidding!
http://gbusch.altervista.org



Edited 2 time(s). Last edit at 04/25/2016 10:45AM by foliator.

Options: ReplyQuote
Re: How to launch external app in KM?
Posted by: siria
Date: April 25, 2016 07:03AM

While we're at it, let me throw in yet another possibility ;-)
More lines, but less wild slashing:

$_prog="C:/Users/(username)/Documents/Apps/Mempad.exe";
$_file="C:/Users/(username)/Documents/Personal/Organizer.pad";
exec($_prog." ".$_file);
$_prog=""; $_file="";


Exec can also call the system-default program for a file type, which is handy for macros for multiple users, but am not 100% convinced that in 1-user cases everyone will find that easier as hard coded paths. Anyway, just for completeness cool smiley

$ext="pad"; &getExtensionHandler;
$_file="C:/Users/(username)/Documents/Personal/Organizer.pad";
exec(sub("%1",$_file,$cmdline));
$_file=""; $ext=""; $cmdline="";


("sub" translates to: replace in the commandline found in the registry the placeholder %1 with the given file)



Edited 2 time(s). Last edit at 04/25/2016 07:11AM by siria.

Options: ReplyQuote
Re: How to launch external app in KM?
Posted by: foliator
Date: April 25, 2016 10:42AM

Quote
siria
("sub" translates to: replace in the commandline found in the registry the placeholder %1 with the given file)

Easy enough to remember: "sub" = "substitute".

Anyway, I can see the logic in those macros, having recognized the definition of variables from my early experiments with BASIC. The last BASIC program I wrote was in 1993, when running DOS on a 286 computer. It was a program to calculate and display the phases of the moon in real time. I was pretty proud of it and had even compiled it into an .EXE, but when I got my first Windows-capable computer (a 486), development of that program came to a screeching halt. The higher screen resolution would have forced me to recalculate all the coordinates for drawing the circles and semicircles representing the moon phases. I was too lazy to do that. sleepy smiley

Now I can't remember how I even got that far. confused smiley The only coding I'm willing to do nowadays is writing simple batch files, HTML, CSS and these mini-macros of mine.

-----

Using KM 75.0 on Windows 7 (x86)

My personal Website. No ads, no scripts, no cookies -- no kidding!
http://gbusch.altervista.org

Options: ReplyQuote
Re: How to launch external app in KM?
Posted by: guenter
Date: April 25, 2016 10:52AM

Thank You two.

Options: ReplyQuote
Re: How to launch external app in KM?
Posted by: siria
Date: April 26, 2016 04:02AM

Oh yes, BASIC smiling smiley Still remember it fondly from that little course in school, ages ago. Which doesn't mean that I'd remember any of the code and certainly never got as far as you, but loved it for its simplicity and was GREAT fun! In those regards certainly kindred to macrolanguage. And anything more complicated would be beyond my limited talents.
But I felt already at the time that it would be a very bad idea to consider programming a possible job career, because it's just too addictive! Interesting tasks or difficult probs wouldn't get out of my head when leaving the office, instead strangle and haunt me 24h a day, still programming half asleep in bed with closed eyes, unable to fall asleep, then perhaps even in dreams, LOL!

Options: ReplyQuote
Re: How to launch external app in KM?
Posted by: foliator
Date: April 26, 2016 05:50AM

I know what you mean by programming addiction; I got so wrapped up in it one day that I forgot about the time and was late getting to work.

My first experience with computers was on a TRS-80, which used a cassette tape recorder for storing programs and a black and white TV as a monitor. Then I got a pocket computer, then a Model 100. All of these were by Radio Shack, and none of them had more than 16K of RAM, although they were awfully expensive!

Back then I did consider a career in programming and started taking a course for that, but eventually dropped out, since it was too difficult to fit my studies in while working full-time at something else. Not only that, but after day upon day of preliminaries, our instructor finally attempted to teach us COBOL and failed miserably. Not one student could get a program to compile correctly. It's quite possible that the instructor couldn't even teach a dog to bark. grinning smiley

Computers finally did earn me a living later on, however, because I spent about 6 years teaching business applications at a commercial college, and did some private consulting on the side. Guess I'm still a bit addicted to computing, but on a retirement pension, so I no longer need to worry about careers. cool smiley

-----

Using KM 75.0 on Windows 7 (x86)

My personal Website. No ads, no scripts, no cookies -- no kidding!
http://gbusch.altervista.org

Options: ReplyQuote


K-Meleon forum is powered by Phorum.