|Finder renaming script?
||[Jun. 17th, 2011|01:36 pm]
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"
set folder "minecraft.jar" of thisFolder as "minecraft-mods.jar"
set file "minecraft-original.jar" of thisFolder as "minecraft.jar"
I get the error, "Expected class name but found """." What am I doing wrong?
Okay, so I officially love you, that works exactly how I want it to, thanks so much :)
I take it that in order to use thisFolder as a placeholder for the path you're handling, you need to put 'as alias' at the end? Also, I notice that you've used colons to denote filepath as opposed to slashes, I presume that's just a convention of which I was unaware?
You've written the if statement in order that AppleScript checks the names of the folders rather than the way I had done it in my original script – is there a reason that this works better than the way I was trying to do it? I can see why my renaming wouldn't have worked, that was clearly me being stupid! :)
Hope you don't mind me asking questions, but I like knowing where I was going wrong and it seems to me that asking is the best way to achieve that.
2011-06-17 11:50 pm (UTC)
Re: try this
Yeah, slashy paths are POSIX, which are relatively new to AppleScript. There are some very rudimentary commands for dealing with those, but AppleScript prefers the older HFS-style paths, which use colons. An alias is always an HFS path. The reason we have to specify that these things are aliases, though, is that Finder prefers to use an even more arcane form of references, which are long cumbersome sentences like "the file of the folder of the disk of whatever."
As to your other question, I tried using the "exists" property, but the Finder kept reporting "false" no matter what. I guess you could chalk that up to one of AppleScript's many "unpainted corners," or places where magical things could happen, but for whatever don't. In my experience, I just work with the data that the program is willing to give up. In this case, I'm asking for a list of names, and then looking through the list to find a match.