Resolved Copy files from the Script bundle? Please help!

Discussion in 'Mac Programming' started by 1theo0, Jul 21, 2012.

  1. 1theo0, Jul 21, 2012
    Last edited: Jul 21, 2012

    macrumors newbie

    1theo0

    Joined:
    Jul 21, 2012
    #1
    Hello, I need some help writing an apple script that will copy some files from itself to a folder on the computer.
    I've created a script and saved it as an app, then copied a folder in its Resources folder. I need to make the script copy the files from that folder outside the app and place them in the user's "Documents" folder. Please help me out, thank you.
     
  2. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    Standard Additions has commands that can be used to get paths to bundle resources and various standard locations, for example:

    Code:
    path to documents folder
    path to resource "main.scpt" in directory "scripts"
     
  3. thread starter macrumors newbie

    1theo0

    Joined:
    Jul 21, 2012
    #3
    Doesn't seem to work, I do not possess a lot of experience in scripting :( Please , could you explain me more?
    I tried this:

    do shell script "cp -RfX "path to folder "Dock-update" in directory "Resources"" "/System/Library/CoreServices/Dock.app/Contents/Resources/"

    Dock-update contains this image (frontline.png) and is located in Contents/Resources of the script bundle. I want all the images from "Dock-update" to be copied in "/System/Library/CoreServices/Dock.app/Contents/Resources/".
     
  4. kryten2, Jul 21, 2012
    Last edited: Jul 21, 2012

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    Code:
    --replace yourfolder with the actual folder name
    set myself to (path to me as string) & "Contents:Resources:yourfolder:"
    -- user's documents folder
    set myDocuments to path to documents folder
    tell application "Finder"
    	set filesList to every item of (myself as alias)
    	duplicate filesList to myDocuments
    end tell
    
    Try this :

    Code:
    set myself to (path to me as string) & "Contents:Resources:Dockupdate:"
    set myDestination to "/System/Library/CoreServices/Dock.app/Contents/Resources/"
    do shell script "cp -RfX " & quoted form of POSIX path of myself & space & myDestination with administrator privileges
    Disclaimer : I'm not responsible if you render your system inoperable or mess up your Dock.

    Note : To see the effect of the changes to your Dock use killall Dock in Terminal or put it in the script.
     
  5. thread starter macrumors newbie

    1theo0

    Joined:
    Jul 21, 2012
    #5
    Oh thank you so much!!! It works perfectly.
    Here, I upload my first script, I've tested it on Snow Leopard, but I assume Leopard and Lion would also work fine.
    Actually, just to make sure, go to
    and see if you've got those 14 files:

    frontline.png
    indicator_large.png
    indicator_medium_simple.png
    indicator_medium.png
    indicator_small_simple.png
    indicator_small.png
    openinfinder.png
    resizecursor.png
    resizecursorv.png
    scurve-l.png
    scurve-m.png
    scurve-sm.png
    scurve-xl.png
    separator.png

    Please check my script out if those files exist! :D And thanks for helping me out!
     

    Attached Files:

  6. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #6
    Can't really tell what the script does since it is run-only and can't be read, but I'm not much of a fan of modifying system files, especially since most of them are code-signed.
     
  7. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #7
    I'm with Red Menace on this one. If you want feedback on your script/app saving it as run-only is a big no no. For all we know it could contain some code to wipe a drive or other bad stuff.
     
  8. thread starter macrumors newbie

    1theo0

    Joined:
    Jul 21, 2012
    #8
    Ok, here's the readable file, although I wouldn't have such malevolent thoughts... Please try it out! I used the original Mountain Lion Dock resources, and only applied a bit more transparency. Thanks! :)
     

    Attached Files:

    • Dock.zip
      File size:
      991.7 KB
      Views:
      37
  9. macrumors 603

    Joined:
    Aug 9, 2009
    #9
    Anyone who did have such malevolent thoughts would also say they didn't. Evil doesn't masquerade as Evil, it dresses itself as Good or Banality.
     
  10. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #10
    I wish I had a way with words like that.

    @1theo0

    I don't think all those do shell script lines are necessary. I would use something like this :

    Code:
    set mydockUpdate to (path to me as string) & "Contents:Resources:Dockupdate:"
    set mydockRestore to (path to me as string) & "Contents:Resources:originaldockrestore:"
    set myDestination to "/System/Library/CoreServices/Dock.app/Contents/Resources/"
    display dialog "Welcome! This script will help you obtain the new Mac OS X Mountain Lion Dock. Please make sure you run Mac OS X 10.5 (Leopard) or a newer version. Open the Apple menu () and select 'About This Mac' to find out what OS you run. You can also restore the original Dock." buttons {"Restore original Dock", "OK"} default button 2
    if the button returned of the result is "OK" then
    	myDialog("You will be required to type in your password to replace the original Dock files. Don't worry, the script is also able to restore it!")
    	do shell script "cp -RfX " & quoted form of POSIX path of mydockUpdate & space & myDestination with administrator privileges
    	myDialogDockRestart()
    	mydockKill()
    else
    	myDialog("You will be required to type in your password to restore the original Dock files.")
    	do shell script "cp -RfX " & quoted form of POSIX path of mydockRestore & space & myDestination with administrator privileges
    	myDialogDockRestart()
    	mydockKill()
    end if
    on myDialog(myMessage)
    	display dialog myMessage buttons {"OK"} default button 1
    end myDialog
    on myDialogDockRestart()
    	display dialog "The Dock now needs to be restarted. All your minimised windows will expand." buttons {"OK"} default button 1
    end myDialogDockRestart
    on mydockKill()
    	do shell script "killall Dock"
    end mydockKill
    
     
  11. thread starter macrumors newbie

    1theo0

    Joined:
    Jul 21, 2012
    #11
    I would have loved cleaning my script up like this, I thought about directly commanding it to replace the existing files and tried it out, but it failed! Even the terminal failed! Hence, I had to make my script firstly delete the files before copying the new ones there.
    I have to agree, it seems indeed suspicious to post a run-only file, sorry!

    I've never heard of these commands before:
    So , I see the "set x to y" is a command for assigning a shortcut for a path, right? And I am able to use this shortcut (x) in the next commands.
    Also, Contents:Resources seem to be separated with ":", therefore each time I use ":" for defining a path the script will find the file within it, wherever the app is?
    One more question: what is POSIX?

    Thank you anyhow for helping me. :)
     
  12. kryten2, Jul 22, 2012
    Last edited: Jul 22, 2012

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #12
    myself and myDestination are variables. A variable is a named container in which to store a value. When AppleScript encounters a variable, it evaluates the variable by getting its value. AppleScript variables can hold values of any class.

    More info :

    Tutorials : http://macscripter.net/viewtopic.php?id=25631

    Applescript, variables etc : https://developer.apple.com/library/mac/#documentation/applescript/conceptual/applescriptlangguide/introduction/ASLR_intro.html#//apple_ref/doc/uid/TP40000983-CH208-SW1

    Applescript and POSIX paths : http://www.satimage.fr/software/en/smile/external_codes/file_paths.html

    POSIX : http://en.wikipedia.org/wiki/POSIX
     
  13. macrumors newbie

    Joined:
    May 21, 2012
    #13
    I messed up my Mountain Lion's dock, cloud someone please post the default, unchanged Dock.app from 10.8, please?
     

Share This Page