I have to agree bash is the way to go here, Applescript file handling is ... odd. That said, though, sometimes you want to handle files in an odd, esoteric, way. So, to get your script to compile (maybe function, I dunno) you would first want to translate from posix notation by changing "set this folder to ..." to "set this folder to posix file ... " You can run that as a script by itself to see what the result is. Assuming that translates well, finder might accept it, might not, you just have to fiddle with it. It might need to also have an "... as alias" tacked on the end.
As for the actual thing your compiler is hiccuping on there, that line:
set file "minecraft.jar" of thisFolder as "minecraft-original.jar"
...doesn't make sense. The word "as" is only for changing types, like "as text" or "as alias" not changing names. To change a name you would say something like:
set name of file "minecraft.jar" of thisFolder to "minecraft-original.jar"
...using the "set ... to" model, not "set ... as." Changing the grammar will make it compile. Again, I don't know if the Finder will behave as expected, you might check its dictionary, sometimes they prefer different commands.
Also, I believe Automator has Finder actions that can handle all this as well, if you'd rather not mess around with semantics. ;)
I don't know if Automator can handle if statements, can it? That's why I was attempting to do it via AppleScript as opposed to Automator (I actually basically understand how to use Automator, as opposed to being a complete newbie with AppleScript).
Ah, they told me they were going to add those. Looks like they just added variables and loops in my copy, no conditionals to be found, just filters. Well, you can still put them in by using the AppleScript action, but at that point it's more trouble than it's worth.
So, have we sorted your script yet? (haven't read the comments above)
tell application "Finder" get the home as alias as text set thisFolder to the result & "Dropbox:Minecraft:minecraft:bin:" as alias if the name of thisFolder's folders contains "minecraft-mods.jar" then set the name of folder "minecraft.jar" of thisFolder to "minecraft-original.jar" set the name of folder "minecraft-mods.jar" of thisFolder to "minecraft.jar" else set the name of folder "minecraft.jar" of thisFolder to "minecraft-mods.jar" set the name of folder "minecraft-original.jar" of thisFolder to "minecraft.jar" end if end tell
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.
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.
As for the actual thing your compiler is hiccuping on there, that line:
set file "minecraft.jar" of thisFolder as "minecraft-original.jar"
...doesn't make sense. The word "as" is only for changing types, like "as text" or "as alias" not changing names. To change a name you would say something like:
set name of file "minecraft.jar" of thisFolder to "minecraft-original.jar"
...using the "set ... to" model, not "set ... as." Changing the grammar will make it compile. Again, I don't know if the Finder will behave as expected, you might check its dictionary, sometimes they prefer different commands.
Also, I believe Automator has Finder actions that can handle all this as well, if you'd rather not mess around with semantics. ;)
Reply
Reply
So, have we sorted your script yet? (haven't read the comments above)
Reply
get the home as alias as text
set thisFolder to the result & "Dropbox:Minecraft:minecraft:bin:" as alias
if the name of thisFolder's folders contains "minecraft-mods.jar" then
set the name of folder "minecraft.jar" of thisFolder to "minecraft-original.jar"
set the name of folder "minecraft-mods.jar" of thisFolder to "minecraft.jar"
else
set the name of folder "minecraft.jar" of thisFolder to "minecraft-mods.jar"
set the name of folder "minecraft-original.jar" of thisFolder to "minecraft.jar"
end if
end tell
Reply
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.
Reply
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.
Reply
Reply
Leave a comment