Running Applications and Websites using the Launch URL Command
1. The Launch Command (using default applications) Launch opens up websites , documents, pictures, etc from LiveCode. Many documents and information are already in PDF's or other types of documents. The documents can be opened either in or out side of your app. We will look at both ways of doing this.
A. Opening up a Website in the default browser (e.g. I.E. or Safari)
This opens up the url in the default browser program (i.e. on PCs, Safari on Macs)
launch document "http://google.com" ===> opens up "Google.com" in Internet Explorer (PC) or Safari (Mac) launch url "http://google.com" ===> opens up "Google.com" in Internet Explorer (PC) or Safari (Mac)
B. Opening up a Website in a different browser (e.g. Chrome)This opens up the url in the browser program that you specify (i.e. Chrome, Marathon, etc)
launch "http://google.com" with "C:\Program Files\Google\Chrome\Application\chrome.exe" ===> opens up "Google.com" in Chrome
C. Opening Up a File (word, pdf, spreadsheet, PowerPoint, etc) in its Default Application. The simplest way to display a document is to use the "launch document" command. It is the easiest way. This opens the document with the default program on your computer e.g Word, Excel, Safari, Chrome, etc
e.g. This will access the PDF document in your default "Documents" or "My Documents" folder launch document "MyPDF.pdf" launch "/Documents/Projects/test.txt" with myApp launch "http://google.com" with "C:\Program Files\Google\Chrome\Application\chrome.exe" launch url "http://www.myschool.com/docs/myPDF.pdf" launch url "file:/Users/ben/Desktop/test.pdf"
launch document "Bell Schedule.pdf" ==> opens up "Bell Schedules" in Adobe Reader (it has the pdf extension) launch document "MyReport.doc" ===> opens up "MyReport" in Microsoft Word (it has the ,doc extension) launch document "Expenses.xls" ===> opens up the spreadsheet "Expenses" in Microsoft Excel (it has the xls extension) launch document "Presentation.ppt" ===> opens up "Presentation" in PowerPoint (it has the ppt extension) launch document "MyReport.pages" ===> opens up "MyReport" in Pages (it has the ,pages extension) launch document "Expenses.xls" ===> opens up the spreadsheet "Expenses" in Numbers (it has the xls extension) launch document "Presentation.key" ===> opens up "Presentation" in Keynote (it has the key extension) You can open a document in another folder if you specify the entire path launch document "/User/Admin/Documents/Bell Schedule.pdf" launch document "/Users/mike.smith/My Documents/Bell Schedule.pdf" You can open a document from a website, if you specify the entire path launch url "http://www.myschool.com/docs/Bell%20Schedule%20.pdf" Notes: URL names are not allowed to have spaces in them launch url "http://www.myschool.com/docs/Bell Schedule .pdf" will not work
instead replace spaces with %20 (the unicode for space) launch url "http://www.myschool.com/docs/Bell%20Schedule%20.pdf"
or do that manually or with the command:
replace " " with "%20" in myUrl
The better way (but more difficult one) is by creating your own browser window inside of LiveCode. You stay inside of your Livecode application and have full control over what the user does. This will be covered in the next lesson
2. Different versions of the Launch Command:
1. Launch url - Opens a url (file/website/application/etc) in the correct application
Use the launch url command to open a url using the default action for the current system. The command performs an action appropriate to the protocol and address provided in the given URL.
Using:
urlToOpen is the url to launch. Can be in the following forms:
• http: url - will launch in the default browser application if available.
• file: path - open the file in the associated application
• tel: url - open the dialer with a given phone number
Examples:
launch url "http://www.runrev.com" launch url "file:/Users/ben/Desktop/test.pdf" launch url "tel:44 7818 8822"
2. Launch Document - Opens a file/document/website/etc with the operating system's default program.
It works the same as you double-clicking on a file. For instance, if you double-click on "My Story.doc" it will automatically open up Microsoft Word because that is the application that is associated with "doc" files.
launch document <document path>
where:
documentPath is the location and name of a file to open with the specified application. If no path is given.it looks in the defaultFolder.
launch document "/myProjects/myLiveCodeProject/help.pdf" ===> a PDF launch document "Report.ppt" ===> a PowerPoint launch document "http://google.com" ===> a website 1. If you want to launch a document with a specific application, use the launch command instead, which allows an application name. 2. If launching the document fails, an error message will be placed into the result, otherwise the result will be empty. If non-empty, the message will be one of the following: "can't open file" - the file was not found or is not accessible "no association" - no application was found to open the document "request failed" - an attempt was made to launch the appropriate application but it was unable to fulfill the request "no memory" - the system ran out of resources or memory while trying to fulfill the request
3. Launch - Opens a file/document/website/etc with a program that you specify or just opens the program
Starts up an application, optionally opening a document in the application.
Launch <document path> with <application path>
where: documentPath is the location and name of a file to open with the specified application. If no path is given.it looks in the defaultFolder. applicationPath is the location and name of the application to start up. If no path is given,it looks in the defaultFolder.
launch "/Documents/Projects/test.txt" with myApp launch "http://google.com" with "C:\Program Files\Google\Chrome\Application\chrome.exe"
To get the path of the application that you want to use: open up Windows Explorer (PC) or Finder (Mac) and find the file. then right click on it and bring up the "properties". Copy the full path and use that in the command
|
|