?

Log in

Finder renaming script? - applescript [entries|archive|friends|userinfo]
applescript

[ website | Apple's AppleScript Home Page ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Finder renaming script? [Jun. 17th, 2011|01:36 pm]
applescript

applescript

[johncoxon]
Hey all.

Before I tell you the script I'm trying to use I want to give you guys an idea of what I'm trying to achieve with it. I'm an avid Minecraft player, and the game places a folder in Application Support called Minecraft. In this folder is a file: /bin/minecraft.jar. In order to mod the game, you rename the file to minecraft-original.jar, unzip and then put new files in the resulting minecraft.jar folder. In order to bring back your vanilla Minecraft installation, you rename the folder minecraft.jar to minecraft-mods.jar, and the file called minecraft-original.jar is renamed minecraft.jar.

What I am attempting to do is create an AppleScript that looks to see whether the folder minecraft-mods.jar exists, and if it does, go back to the vanilla build, but if it doesn't, go to the modded build. My proposed script is below:

tell application "Finder"
set thisFolder to "/Users/John/Dropbox/Minecraft/minecraft/bin"
if folder "minecraft-mods.jar" of thisFolder exists then
set file "minecraft.jar" of thisFolder as "minecraft-original.jar"
set folder "minecraft-mods.jar" of thisFolder as "minecraft.jar"
else
set folder "minecraft.jar" of thisFolder as "minecraft-mods.jar"
set file "minecraft-original.jar" of thisFolder as "minecraft.jar"
end if
end tell

I get the error, "Expected class name but found """." What am I doing wrong?
link

Comments:
[User Picture]From: kiodane
2011-06-17 06:10 pm (UTC)
You're right, there is a certain amount of "dumbness" that my script exhibits because to change your mind between mod or vanilla, you actually have to edit the script file and comment/uncomment the lines yourself.

But I think that a Minecraft server is more enjoyed and better managed if you're familiar with Terminal and bash. Applescript is something I love too, but for this it really seems bloated for what you're trying to accomplish.

I also did not mean to say that my above script was meant as a solution to your problem. In fact, it's the solution to MY problem, and I was making it available for you to consider in your journey.

To be honest, even though you explained your end goal, I didn't understand the point of detecting if a folder exists or not and to launch a different version based on that. Again, I think bash is better suited to your goal since I suspect the majority of Minecraft servers are running on Linux, and bash is a common element between Mac and Linux (and therefore more support from the MC server forums).

But XV provided support on your compilation error, something I couldn't do away from my Mac at the time I wanted to contribute my solution to my problem.

If you want to explore bash scripting, I recommend this guide: http://tldp.org/LDP/abs/html/
(Replies frozen) (Parent) (Thread)
[User Picture]From: johncoxon
2011-06-17 06:14 pm (UTC)
I'm not trying to run a server, I'm just trying to run a client. I just want something that, if I want to easily switch between the vanilla client and the modded version, I can use spotlight and hit enter, which seems like a fairly simple implementation of the thing I'm trying to do. It's easier than going to /minecraft/bin and renaming the files every time I want to switch over. So far I haven't had to use any Terminal at all in order to play Minecraft, so integrating this into a Terminal productivity flow would add steps that are unnecessary, as far as I can tell...

I am probably just being dense but I genuinely don't understand how your code would help me achieve the goal I have in mind!
(Replies frozen) (Parent) (Thread)
[User Picture]From: kiodane
2011-06-17 06:19 pm (UTC)
Ah, yes. I did misunderstand you.

I have no personal interest in running a modded client, and therefore cannot help you.

Sorry to waste your time.

Perhaps you could just keep two separate folders, each with their own version of the client. Then you as a human being can decide on which you want.
(Replies frozen) (Parent) (Thread)
[User Picture]From: johncoxon
2011-06-18 12:01 am (UTC)
Thanks for your help, nonetheless :)
(Replies frozen) (Parent) (Thread)
[User Picture]From: kiodane
2011-06-17 06:24 pm (UTC)
but I genuinely don't understand how your code would help me achieve the goal I have in mind!


In Terminal, you can generally get help on any command by typing "man ". Regular Expressions are an annoying thing to learn, however, but they are useful in other locations like Perl and BBEdit/TextWrangler searches.

A bash script is little more than a series of commands that you would otherwise execute in Terminal by hand.
(Replies frozen) (Parent) (Thread)