Opening a file with it's default program
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 44
- Joined: Thu Jul 19, 2012 1:49 pm
Opening a file with it's default program
Hey guys, first time posting, so far, LOVING livecode!
My question is:
We need to open up a file in it's default associated program (say msPaint for images for example) but as we want to deploy to Windows, Mac OS X, Linux, iOS and Android.
This feature isn't really needed on iOS and Android, but Windows, Mac OS X and Linux are a must. Is there anyway of doing this?
The only other thing I can think of doing is an askFile dialog and getting them to find the program, but if they aren't very computer literate (which is a possibility) we'd like to make it as simple as possible
Cheers in advance
David
My question is:
We need to open up a file in it's default associated program (say msPaint for images for example) but as we want to deploy to Windows, Mac OS X, Linux, iOS and Android.
This feature isn't really needed on iOS and Android, but Windows, Mac OS X and Linux are a must. Is there anyway of doing this?
The only other thing I can think of doing is an askFile dialog and getting them to find the program, but if they aren't very computer literate (which is a possibility) we'd like to make it as simple as possible
Cheers in advance
David
Re: Opening a file with it's default program
If you want the system to launch the default application for that file, look at 'launch document' in the dictionary.
Should work on windows and mac, linux? Not sure if there will be any hiccups there and can't test at the moment.
Should work on windows and mac, linux? Not sure if there will be any hiccups there and can't test at the moment.
-
- Posts: 44
- Joined: Thu Jul 19, 2012 1:49 pm
Re: Opening a file with it's default program
Thanks for the fast reply
I've tried:
and that didn't work.
As far as I could tell that will then look for the application in the default folder, rather than launch the default application.
IT does work when I do something like:
But as this would be windows specific (mspaint that is, the file path here is just to test and can be changed later)
Cheers
David
I've tried:
Code: Select all
put the filename of img "imgImage" of me into tStrFile
launch tStrFile
As far as I could tell that will then look for the application in the default folder, rather than launch the default application.
IT does work when I do something like:
Code: Select all
put the filename of img "imgImage" of me into tStrFile
launch tStrFile with "C:\windows\system32\mspaint.exe"
Cheers
David
Re: Opening a file with it's default program
Look at 'launch document' document being a keyword not a document name. launch document (both words) is a separate entry in the dictionary.
If you "launch document "path/to/file.bmp" it should launch file.bmp in the default application for the system.
Otherwise, yes if you know where a command is you can launch "myfile" with "app path" and on linux you could use shell("which commandtorun") and it would tell you where it is and if it is on the system and in the path. (otherwise it's tells you it can't find it)
If you "launch document "path/to/file.bmp" it should launch file.bmp in the default application for the system.
Otherwise, yes if you know where a command is you can launch "myfile" with "app path" and on linux you could use shell("which commandtorun") and it would tell you where it is and if it is on the system and in the path. (otherwise it's tells you it can't find it)
Last edited by sturgis on Mon Aug 20, 2012 4:01 pm, edited 2 times in total.
-
- Posts: 44
- Joined: Thu Jul 19, 2012 1:49 pm
Re: Opening a file with it's default program
Sorry, I completely misunderstood what you said, I didn't know there was a Launch and a Launch Document, I thought you were referring to Launch [document].
That works brilliantly, thank you.
Now I just need to open it with an editing program as the default may be an image viewer rather than an editor...
Thanks
David
That works brilliantly, thank you.
Now I just need to open it with an editing program as the default may be an image viewer rather than an editor...
Thanks
David
Re: Opening a file with it's default program
EDIT: apparently I'm redundant quite often. Ignore any duplications. Did I mention its early for me?
True, and there is a limit to how much you can protect a user. If mspaint is in the path, AND the path is available to the launch command it might be possible to launch it with just the command name. This way you could just do 'launch "/path/to/file" with "mspaint.exe"
On linux you could use shell and the 'which' command to see if a specific application is available and where it resides in the path at which point you could use the info to specify what app to use. (though there are SO many options..)
And I just tried it on os x and yep. Preview opens for png's. *sigh*
However, the same deal applies on mac. If its in the applications folder you can launch it without specifying the path.
For example
launch "path/to/my/image" with "iPhoto.app" works fine.
So, if paint works for windows you might be able force it to mspaint, mac you can use iPhoto (otherwise you would have to determine what has been installed on the system...) linux? More difficult, there is no telling what image editor if any might be installed. You can use shell("which commandname") to determine if a specific app is available and where it resides. If it isn't found tell the user to install it maybe.
On OS X same deal, if you don't want them to use iphoto (not the greatest editor) you could have them pick an app from the /Applications folder to use for the job and hope they have something installed that will do it.
Sorry if i'm bouncing around a bit, its early for me!
True, and there is a limit to how much you can protect a user. If mspaint is in the path, AND the path is available to the launch command it might be possible to launch it with just the command name. This way you could just do 'launch "/path/to/file" with "mspaint.exe"
On linux you could use shell and the 'which' command to see if a specific application is available and where it resides in the path at which point you could use the info to specify what app to use. (though there are SO many options..)
And I just tried it on os x and yep. Preview opens for png's. *sigh*
However, the same deal applies on mac. If its in the applications folder you can launch it without specifying the path.
For example
launch "path/to/my/image" with "iPhoto.app" works fine.
So, if paint works for windows you might be able force it to mspaint, mac you can use iPhoto (otherwise you would have to determine what has been installed on the system...) linux? More difficult, there is no telling what image editor if any might be installed. You can use shell("which commandname") to determine if a specific app is available and where it resides. If it isn't found tell the user to install it maybe.
On OS X same deal, if you don't want them to use iphoto (not the greatest editor) you could have them pick an app from the /Applications folder to use for the job and hope they have something installed that will do it.
Sorry if i'm bouncing around a bit, its early for me!
-
- Posts: 44
- Joined: Thu Jul 19, 2012 1:49 pm
Re: Opening a file with it's default program
Ah don't worry about it. Thanks for the help and we'll probably test each of those options out to see which we prefer.
Cheers
David
Cheers
David