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

Apothocary

macrumors newbie
Original poster
Jun 9, 2015
1
0
Writing a little script for backing up my Minecraft saves. It zips up the directory and retitles it with current date a time. Only, it doesn't work.

I'm sure there are a bunch of POSIX commands lacking and other such bumpf... any help though?

Thanks in advance!

Code:
set timeStamp to do shell script "/bin/date +%d/%m/%Y_%T"
set ZIPfile to quoted form of (timeStamp & ".zip")
set saveFolder to alias "Users:Hermes:Library:Application Support:minecraft:saves"

display dialog "Do you want to backup your world(s) first?" buttons {"No, just play", "Yes, please!"}
if result = {button returned:"No, just play"} then
tell application "Minecraft" to activate
else if result = {button returned:"Yes, please"} then
end if
do shell script "zip -r -j " & ZIPfile & "" & saveFolder
tell application "Minecraft" to activate
end

It spits out an error to the tune of "zip error: Nothing to do!"
 
Last edited:

chown33

Moderator
Staff member
Aug 9, 2009
10,893
8,702
A sea of green
Did you get the script from a website, or did you make it up yourself? If it's the former, please post the URL. If it's the latter, what other scripts have you written?

What happens when you type the command into a Terminal window manually, in exactly the format the do shell script executes it? Post the command you enter, the output, and an ls -l on any files produced. If you don't understand some part of that, ask a specific question and identify which part.

You almost certainly need a Posix path expression in there somewhere, but exactly where is going to depend on what the working Terminal command looks like. For example, add the second line shown here:
Code:
set saveFolder to alias "Users:Hermes:Library:Application Support:minecraft:saves"
set savePath to Posix path of saveFolder  -- add this line

I suggest using AppleScript's log statement to tell you what each step of the script produces. For example, what savePath is, as compared to what saveFolder is.

I also suggest starting with just the first line of the script. Run it. Does it complete successfully? What is the result? If the result is what you expect, then add the second line and run it again. Successful completion? Result?

If somethine doesn't complete successfully, post the entire script up to that point, and the complete exact text of any error message. If there are no error messages but the result isn't what you expect, post the exact text that's AppleScript's description of the result (copy and paste from AppleScript Editor).

Debugging is mainly a process of Confirming Your Expectations. That implies you know what to expect at each step, so you can tell whether what happens is what's expected.


EDIT
Please post your exact OS version. AppleScript syntax may depend on what OS you're using.
 
Last edited:

dylanryan

macrumors member
Aug 21, 2011
57
2
Two other things that will probably need to be fixed.

1)
Code:
do shell script "zip -r -j " & ZIPfile & "" & saveFolder
Even if saveFolder has a POSIX path in it (per chown33's suggestion), since you have the empty string between that path and the zip file, it will be read by the shell as one big unit. So, zip will just see one argument, and it needs two. Put a space in between the consecutive double quotes.

2) Your date format includes slashes and colons (i.e. today's date would format as "09/06/2015_19:36:16"). This is then used as the file name for zip. The shell will interpret the slashes as directory delimiters (so will want a folder "09" to exist, and within that, will want "06", and within THAT, will make a zipfile named "2015_19:36:16.zip" ). And then the colons will display in Finder (and other GUI apps) as slashes due to the way colons are handled in file names. This won't stop it from working (though I don't think zip will create directories to place the zip in, so lack of proper directories would stop it), but will likely be very different from what you expect. If you want a single file named with the data and time, avoid slashes and probably colons too.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.