How to compile 4 actions into 1 button?

Discussion in 'Mac Basics and Help' started by Josias, Jan 22, 2010.

  1. Josias macrumors 68000

    Josias

    Joined:
    Mar 10, 2006
    #1
    Hey, good to be back :D

    I recently pulled out my old Halo cd, and it looks great on my 13" MBP. I don't wanna lug around the CD all the time though, so I copied it as a .dmg to my harddrive.

    Every time I start Halo, I have to open Toast, mount the .dmg, close toast and then open Halo. Is there some way for these four actions to be compiled into a single button in for example the dock?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    If all of the actions are AppleScriptable (will depend on Toast which I don't have) then yes: you could write an AppleScript.
     
  3. Josias thread starter macrumors 68000

    Josias

    Joined:
    Mar 10, 2006
    #3
    I assume they are scriptable, but I never used AS before. Any tips? :p
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Use Google! Seriously for what you want it's going to be something simple like (although this won't actually work as I don't know what Toast's scripting dictionary looks like):

    Code:
    tell application "Toast"
    mount <path to dmg>
    end tell
    tell application "Halo"
    activate
    end tell
    
    Basically it's the line with mount you need to research and make work.
     
  5. Josias thread starter macrumors 68000

    Josias

    Joined:
    Mar 10, 2006
    #5
    So far I have:

    launch application "Toast Titanium"
    tell application "Toast Titanium"
    open alias / Users / Josias / documents / Halo / Halo
    end tell

    Applescript keeps telling me that "Users" is an undefined variable
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    You'll need to do something to convert those bare words into a path: perhaps enclosing the path in quotes might work...
     
  7. Josias thread starter macrumors 68000

    Josias

    Joined:
    Mar 10, 2006
    #7
    launch application "Toast Titanium"
    tell application "Toast Titanium"
    open alias "/ Users / Josias / documents / Halo / Halo.dmg"
    end tell

    is accepted by Applescript, but: "Toast Titanium reported an error: a file couldn't be found" :confused:
     
  8. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #8
    Code:
    do shell script "hdiutil attach /Users/Josias/documents/Halo/Halo.dmg"
    activate application "Halo"
    Done :D I do like AppleScript.

    Also, 'tell'ing an app to do something always activates it.
     
  9. Josias thread starter macrumors 68000

    Josias

    Joined:
    Mar 10, 2006
    #9
    I don't understand.
     
  10. BlueRevolution macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #10
    I'll do you one better. I've never used it personally, but you should just be able to run a shell script like:

    open -a /Applications/ToastMount.app /path/to/Halo.dmg
    sleep 10
    open /Applications/Halo.app


    Or if you want to wrap it in AppleScript I guess you could just wrap it up in

    do shell script "open -a /Applications/ToastMount.app /path/to/Halo.dmg"
    do shell script "sleep 10"
    do shell script "open /Applications/Halo.app"
     
  11. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #11
    Copy and paste that into Script Editor (with the correct path). Then in the editor go to "Save As..." then in the 'File Format' drop down, select 'Application'.

    Drag the resulting application into your dock.
     
  12. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #12
    My way doesn't need anything additional. You also don't need the "sleep 10" portion because the "do shell script" always waits until the shell action exits before moving on.
     
  13. Josias thread starter macrumors 68000

    Josias

    Joined:
    Mar 10, 2006
    #13
    Win! Thanks :D
     
  14. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #14
    I see this is fixed now, but I would note paths don't have spaces: "/ Users /" is very different from "/Users/"
     
  15. Josias thread starter macrumors 68000

    Josias

    Joined:
    Mar 10, 2006
    #15
    Thanks for your help everyone (and you're probably right robbieduncan) :)

    However, now is the time when my noobness is revealed: Can I run an Applescript from the Dock, without launching Applescript? Since this was actually intended as a 1-click start for Halo

    Edit: Here is what I'm using now:

    do shell script "open -a /Applications/ToastMount.app /Users/Josias/Documents/Halo/Halo.dmg"
    do shell script "sleep 10"
    do shell script "open /Applications/Halo.app"
     
  16. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #16
    Alright...why didn't I win?

     
  17. Josias thread starter macrumors 68000

    Josias

    Joined:
    Mar 10, 2006
  18. BlueRevolution macrumors 603

    BlueRevolution

    Joined:
    Jul 26, 2004
    Location:
    Montreal, QC
    #18
    That's true, but it depends how ToastMount works. I figured adding an extra 10 seconds wouldn't hurt, although I'm sure that could be reduced to 2 or 3 seconds.
     
  19. Josias thread starter macrumors 68000

    Josias

    Joined:
    Mar 10, 2006
    #19
    Yep, I got "sleep 2" in place now, and works just fine.
     

Share This Page