Have been reading through some teach yourself stuff and I’ve been unable to find the answer to my question, being:
How would one recommend writing a script that will take my selected item (.html document) and open it in Firefox?
Thank you.
Have been reading through some teach yourself stuff and I’ve been unable to find the answer to my question, being:
How would one recommend writing a script that will take my selected item (.html document) and open it in Firefox?
Thank you.
hi and welcome brian!
Something like this?
tell application "Finder"
set selectedItems to selection
if (count of selectedItems) < 1 then
--there is nothing selected
return
end if
set theFile to POSIX path of (item 1 of selectedItems as string)
if theFile ends with ".html" then
do shell script "open -b org.mozilla.firefox " & quoted form of theFile
end if
end tell
So freakin’ sweet! Thank you very much! It’s starting to make a little more sense now! However, may I ask why it was -b org.mozilla.firefox instead of just listing firefox by itself?
Even simpler, if you’re using the Finder’s selection:
tell application "Finder" to open selection using application file id "org.mozilla.firefox"
Firefox isn’t noted for being particularly scriptable, but v3.6.13 does appear to implement the standard application command ‘open’, so if you have aliases to the file(s) you want to open, you can script it directly:
set htmlFile1 to (choose file of type "public.html")
set htmlFile2 to (choose file of type "public.html")
tell application "Firefox"
activate
open {htmlFile1, htmlFile2}
end tell
I have Firefox set up to open new windows in new tabs instead. The first of the above scripts opens the files in different tabs of the same window; the second opens them in separate windows.
Using the application file’s ID saves having to know its exact name and where it is, although obviously you then have to know what its ID is!
Well your script doesn’t checks if the selection is really a html file. Then the TS asked for a single file so I cleared out multiple selections by opening only the first item of the selection. So your command isn’t only simpler it’s also different. I agree that it looks much nicer