open file on button click in HTML, auto load dvd 4 Mac&PC - help

Discussion in 'Web Design and Development' started by DoFoT9, Sep 19, 2009.

  1. DoFoT9 macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #1
    hey all

    im trying to create a DVD with a bunch of mac and pc software on it. the mac software is in .DMG format, the pc software is in .exe format. i have a few questions.

    1. when the dvd is put into a computer i would like a html document to open (i can already do this on the PC side of things), how does one do it for the mac side? is toast able to do it maybe?

    2. inside the html document there are buttons to either the mac or pc version (there are seperate buttons for mac and pc). how can i make it so that when you hit (for example) the mac "handbrake.app" button that the handbrake.dmg file opens?

    thanks in advance

    DoFoT9

    p.s. im back off to work for a good 5 hrs so ill be back later
     
  2. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #2
    ok so apparently one cannot autorun any file from osx (to dangerous). i guess that doesnt matter as i can include a description with the CD to open the index.html file.

    i am still struggling with the button clicks.

    Code:
    <button type="button">Mac</button>
    Code:
    <button type="button">PC</button>
    but then what :-S maybe some scripting or something?
     
  3. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #3
    http://www.javascripter.com/faq/operatin.htm

    Some really simple JS to determine which button appears.

    EDIT: preface: the html at the bottom will simply go to the finder and highlight the file in question and the user will have to double click on the dmg manually. Unfortunately that leads to complications because not all users will copy the file and will wonder where their app has gone. To that end I suggest you make a little script (applescript/python/shell) that you point to instead of the .dmg and make them run that.

    Applescript: you will need to have to save this code as an Application and as 'Run Only'. (hmm, this scripting is very black box and the user cannot see the script in it. You're better figuring off how to write this in proper terminal scripting instead, but I'm not up to scratch on that yet, just use the applescript without the front bits).
    Code:
    --comment: will open the dmg, copy a targeted file inside and unmount
    --did a quick test, seems to work as it should
    do shell script "hdiutil attach /Volumes/dvd_goodies/goodie.dmg"
    do shell script "cp /Volumes/your_dmg/path_to_file/theapp.app /Applications/"
    do shell script "hdiutil detach /Volumes/your_dmg"
    
    HTML
    Code:
    <html>
    <head>
    <script type="text/javascript">
    	function openfile(thefile) {
    		location.href = "/Volumes/dvd_full_of_goodies/files/" + thefile + ".dmg"
    	}
    </script>	
    </head>
    <body>
    <form>
    	<input type="button" value="Hello World" onclick="openfile('handbrake')">
    <form>
    </body>
    </html>
     
  4. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #4
    wow thanks sandwitch! Thats incredible :)
    Im pretty bad with anything programming so i think that i might just use what you provided, i will include an explanation of what happens with the dvd in a text file or in the html file so users can read it.

    As for the autoload, i will just do what all other discs do and have the image popup and an arrow saying 'click me' lol.

    Thanks again!
     
  5. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #5
    im sorry sammich but im trying to get that script to work but nothings happening when i click the button.

    the file location of say handbrake is "Users/dofot9/desktop/GLITCHS Planning/Included DVD/Softwares/Mac" then the Handbrake_0.9.3.dmg is in there. this of course wont be the location of the final DVD, im guessing you do the "/Volumes/DVD Name/File Location" for that?

    this is the script.

    Code:
      <script type="text/javascript">
    function openfile(Handbrake_0.9.3) {
    location.href = "/Users/dofot9/Desktop/GLITCHS Planning/Included DVD/Softwares/Mac/" + Handbrake_0.9.3 + ".dmg"
    }
      </script>
    
    this is the button. i am confused about the naming of the files and whatnot, any help would be greatly appreciated :D
    Code:
                <form>
                  <input value="Installer"
     onclick="openfile('handbrake')" type="button"></form>
    
    DoFoT9
     
  6. Cerebrus' Maw macrumors 6502

    Joined:
    Mar 9, 2008
    Location:
    Brisbane, Australia
    #6
    I believe the problem is stemming from the fact that you are assigning the value 'handbrake' to the variable 'Handbrake_0.9.3'.

    If the file location is going to be static (IE, never changes), you dont have to pass the location to the script, just always call it.

    Code:
                <form>
                  <input value="Installer"
     onclick="openfile()" type="button"></form>
    

    which would call :

    Code:
      <script type="text/javascript">
    function openfile() {
    location.href = "/Users/dofot9/Desktop/GLITCHS Planning/Included DVD/Softwares/Mac/Handbrake_0.9.3.dmg"
    }
      </script>
    


    If you need it to be dynamic (so the script will handle an input) you could use.



    Code:
                <form>
                  <input value="Installer"
     onclick="openfile('Handbrake_0.9.3')" type="button"></form>
    
    which would call :

    Code:
      <script type="text/javascript">
    function openfile(location) {
    location.href = "/Users/dofot9/Desktop/GLITCHS Planning/Included DVD/Softwares/Mac/"+location+".dmg"
    }
      </script>
    

    In our original code, you have called the function ('Handbrake_0/9.3') , which means thats the variables name not value.

    So, I believe in your original location, it was looking for a file called
    '/Users/dofot9/Desktop/GLITCHS Planning/Included DVD/Softwares/Mac/handbrake.dmg
     
  7. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #7
    Righty o. In the javascript portion you have a function which takes an argument. That argument in the function (called "thefile") will store the value 'Handbrake_0.9.3' when you click on the button in the HTML button with the onclick=openfile('Handbrake_0.9.3'). When the function body executes in the example below will replace 'thefile' with 'Handbrake_0.9.3' and results in the finder opening the location to "/Volumes/...files/Handbrake_0.9.3.dmg".

    Code:
    <html>
    <head>
    <script type="text/javascript">
    	function openfile(thefile) {
    		location.href = "/Volumes/dvd_full_of_goodies/files/" + thefile + ".dmg"
    	}
    </script>	
    </head>
    <body>
    <form>
    	<input type="button" value="Hello World" onclick="openfile('Handbrake_0.9.3')">
    <form>
    </body>
    </html>
     
  8. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #8
    i got it working, well.. opening up the location of the dmg using the static code that you provided.

    Code:
      <script type="text/javascript">
    function openfile() {
    location.href = "/Users/dofot9/Desktop/GLITCHS Planning/Included DVD/Softwares/Mac/Handbrake_0.9.3.dmg"
    }
      </script>
    
    <form>
    <input value="Installer" onclick="openfile()"
    type="button"></form>


    that does open the folder containing the dmg.

    should i probably bypass this and make the button open up the script that you linked earlier so that it installs it? (ie places in the app folder).

    thanks sammich, ur awsome :D
     
  9. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #9
    ok, i now have the dynamic code working so that i dont need a million scripts :D this is sweet as!!

    thanks so much mate

    now to figure out how to implement the script!
     
  10. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #10
    It's what I would recommend. It's almost completely transparent to the user. If I can make one more addition to that script so that it highlights whats just been copied.
    Code:
    do shell script "hdiutil attach /Volumes/dvd_goodies/goodie.dmg"
    do shell script "cp /Volumes/your_dmg/path_to_file/theapp.app /Applications/"
    do shell script "hdiutil detach /Volumes/your_dmg"
    [B]do shell script "open -R /Applications/theapp.app[/B]
    Oh you! :D
     
  11. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #11
    you just answered my question without even reading the newer post that i put in! you truly are a raw talent lol. that script seems really easy to implement, i will need a seperate script for each app i take it? thats no problem really..
     
  12. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #12
    Unfortunately you will need to make one of these little applescripts for each app.

    Copy and paste the script into 'Applescript Editor' and then save it similar to the screenie. In the script itself you will need to obviously figure out the location/name of the app to copy, the name of the mounted volume of the dmg.
     

    Attached Files:

  13. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #13
    thats ok im sure its easy to change, i just need to figure out how to reference the names from the DVD, it will be easy enough just use /Volumes/file path etc.

    im having trouble running the script.

    Code:
    do shell script "hdiutil attach /Users/dofot9/Desktop/GLITCHS Planning/Included DVD/Softwares/Mac/Handbrake_0.9.3.dmg"
    do shell script "cp /Volumes/Handbrake/HandBrake.app /Applications/"
    do shell script "hdiutil detach /Volumes/Handbrake.dmg"
    do shell script "open -R /Applications/HandBrake.app"
    
    it highlights the first line and says "hdiutil: attach: extra image argument "Planning/Included" - "/Users/dofot9/Desktop/GLITCHS" already specified". the name of the handbrake image is "Handbrake_0.9.3", im not sure what the error is saying though :\
     
  14. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #14
    I think the error lies in the fact you have a space in your command.

    You can either wrap the whole path in single inverted commas:

    Code:
    do shell script "hdiutil attach [B]>'<[/B]/Users/dofot9/Desktop/GLITCHS Planning/Included DVD/Softwares/Mac/Handbrake_0.9.3.dmg[B]>'<[/B]"
    or use the escape character after every space "\"

    Code:
    do shell script "hdiutil attach /Users/dofot9/Desktop/GLITCHS[B]>\<[/B] Planning/Included DVD/Softwares/Mac/Handbrake_0.9.3.dmg"
    (without the angled brackets of course)
     
  15. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #15
    ingenious!!!!! sorry for my terrible programming skills.

    just gotta put in some delays so that it stops giving out errors. any suggestions on time frames? is there a way to make it wait until the previous line has finished?
     
  16. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #16
    What kinda of errors are you getting? These scripts should wait until the previous command has finished before proceeding.
     
  17. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #17
    hmm ok maybe not, i now get "cp: /Volumes/HandBrake/HandBrake.app is a directory (not copied)."

    so thats just mybad for that.. but hmmm..

    i honestly cant see any errors with it.. :|
     
  18. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #18
    Wow, that one had me stumped for a while. You need make that command with '-R' in front like:

    Code:
    cp -R /Volumes/HandBrake/HandBrake.app /destination_folder
    The flag -R means that it will copy folders and all their contents. In addition, don't add a trailing '/' after the '.app' because that means it will copy the contents of the app, rather than the app itself.
     
  19. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #19
    well, i think its working. it gives THE BIGGEST error list ive ever seen (the window goes off my screen) but it says that it has no permissions to write - this is because i dont have access to the Applications folder as im not admin.

    ok i changed to a directory that i could edit, it all worked fine! but it would not launch the file, apparently the -R attibute isnt allowed when opening? so i took our the -R and it all works fine :D:D

    horrah!
     
  20. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #20
    I was thinking that may be the case. You could give them the options of 'copy to their desktop' (non admin) or 'copy to applications folder (admin pswd needed)', but that would double your work.

    Agh, this is gonna be a mess if you're not an admin. I'll have to get back to you after lunch lol
     
  21. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #21
    yea this can get complicated, but nothing crazy. if only you could check for authorisation or something. but seriously, how many mac users are not admins? (besides me lol).

    have a good lunch, im about to go have some too!

    i think i should be fine now though, cant be that hard appart from creating a prototype disc to make sure i can get the Volume folders correct.

    your help has been invaluable.

    where do you work/what do you do?

    DoFoT9

    :D

    edit: seeing as though using the JS is too hard, i will open the script directly through the button, but how is this done :-S.
    Code:
                <form>
                  <input value="Installer"
     onclick="url=" type="button"></form>
    
    will the URL= field work?

    i also need to research how to do this with .exe files to (dont need a script though as it links directly to the installer).
     
  22. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #22
    BEHOLD! I've tested it with one dmg on my computer and it works for that.

    Code:
    set path_to_dmg to "/Users/dofot9/Desktop/GLITCHS Planning/Included DVD/Softwares/Mac/" -- need trailing slash
    set name_of_mounted_dmg to "Handbrake"
    set path_to_app to "" -- blank if the app is at the root of the dmg
    set name_of_application to "Handbrake.app"
    
    set mount_dmg to "hdiutil attach '" & path_to_dmg & "'"
    do shell script mount_dmg
    try
    	set copy_app_admin to "cp -R '/Volumes/" & name_of_mounted_dmg & path_to_app & "/" & name_of_application & "'" & " /Applications/'"
    	do shell script copy_app_admin with administrator privileges
    on error
    	set dialogresult to display dialog ¬
    		"Admin privileges were not verified. Proceed to copy to desktop?" buttons {"Cancel", "OK"} ¬
    		default button "OK" cancel button "Cancel"
    	if button returned of dialogresult is "OK" then
    		set copy_app to "cp -R '/Volumes/" & name_of_mounted_dmg & path_to_app & "/" & name_of_application & "'" & " ~/Desktop/"
    		do shell script copy_app
    	end if
    end try
    do shell script "hdiutil detach /Volumes/" & name_of_mounted_dmg
    if button returned of dialogresult is "OK" then
    	do shell script "open -R ~/Desktop/" & name_of_application
    else
    	do shell script "open -R /Applications/" & name_of_application
    end if
     
  23. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #23
    oh my god!! thats incredible!! i take it that i will still need a script for each .dmg image?

    i have still yet to figure out how to launch the script directly, the googles aint working.
     
  24. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #24
    EDIT: yeah one for each app/dmg. If there are multiple things to copy from the one dmg, it's a little more complicated. Or you can just make another scripty thing to copy it as well.

    I decided to leave the description for the following reply (this one):

    There are 4 lines at the top of the script. You just fill these out for each dmg and their location, nothing else needs to be changed (I hope). I've filled it in for your Handbrake one, so it should work.

    You can't launch the script directly from the browser, the user has to double click on the script to launch it and do it's work. So make a quick script for handbrake, save it as an Application and as run only. Then fire it up.

    Oh and you can name blank dmg's via Disk Utility (File -> New -> Blank Disk Image) and make it read write. Make it DVD size (in the drop down menu near the bottom) and then create. Now do all your work in that, and when you're ready to burn it, just burn that image (in Disk Utility, select that dmg, then click 'Burn' at the top).
     
  25. DoFoT9 thread starter macrumors P6

    DoFoT9

    Joined:
    Jun 11, 2007
    Location:
    Singapore
    #25
    right. most apps are just normal mac apps i.e. the one file. if there are multiple things then ill have to think of something else.

    what if i save it as an application? can one still not load the application from a html webpage via the use of a link/button? i guess a href link could? :confused:

    im still figuring out how i will do that, i want to create the normal Mac disc where it will automatically open the root folder with an image as the background saying "OPEN THIS FILE TO START", a big arrow pointing to the index.html file.

    THEN i have the PC side of things, i can autorun the index.html file, so thats fine. then i need to implement the buttons/href links to run the .exe files to install the PC software.

    fun fun.

    this work is great sammich! thanks for helping me out, its really appreciated.

    p.s. i get the error "hdiutil: attach failed - Operation not supported on socket"

    on this line
    Code:
    do shell script mount_dmg
    P.S.S. hold on i may have gotten it, did a bit of editing (ever so slightly lol)

    P.S.S.S. its working! horay!!! success!! this is amazing! it asks for a admin password everytime but to run, i wonder why (its a mac os x window not a script window).
     

Share This Page