Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

1theo0

macrumors member
Original poster
Jul 21, 2012
32
0
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.
 
Last edited:
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"
 
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/".
 
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.
 
Last edited:
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
/System/Library/CoreServices/Dock.app/Contents/Resources/
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!
 

Attachments

  • Dock-Update-Mountain-Lion.zip
    991.2 KB · Views: 131
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.
 
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.
 
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! :)
 

Attachments

  • Dock.zip
    991.7 KB · Views: 139
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.

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
 
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:
set myself to (path to me as string) & "Contents:Resources:eek:riginaldockrestore:"
set myDestination to "/System/Library/CoreServices/Dock.app/Contents/Resources/"
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. :)
 
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
 
Last edited:
I messed up my Mountain Lion's dock, cloud someone please post the default, unchanged Dock.app from 10.8, please?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.