PDA

View Full Version : Support with Applescript




Haribo98
May 6, 2012, 06:42 AM
Hi. I'm currently working on a Project for a Game. And I'm stumped on what to do next.
I mean, I know what I want to do, but I don't know how to do it.

I want to run a Shell Script that downloads a bunch of Shell Scripts into ~/Library/Application Support/minecraftmodinstaller/

So far, I've written the scripts but don't know how to implement them.
I would also like to know how I could link the downloaded scripts to buttons in Xcode. I have made the links but don't know the code to make the button open them.

My scripts can be found here (http://mossycc.com/Latest/installers.zip). They're reasonably long...

And the Downloader script can be found here (http://mossycc.com/Latest/installersdl.zip).

P.S - This App is Written in Cocoa-Applescript

Thanks in Advance
- Harry



kryten2
May 6, 2012, 10:09 AM
In Xcode 3.x.x an on clicked theObject handler would to the trick. Things changed with Xcode 4. Check out http://macscripter.net/viewtopic.php?id=30274

on clicked theObject
if title of theObject = "" then
-- run/open your script
end if
end clicked

ps : Your links result in this : Safari can’t open the page “http://mossycc.com/Latest/installersdl.zip” because Safari can’t find the server “mossycc.com”.

Haribo98
May 7, 2012, 02:57 AM
In Xcode 3.x.x an on clicked theObject handler would to the trick. Things changed with Xcode 4. Check out http://macscripter.net/viewtopic.php?id=30274

on clicked theObject
if title of theObject = "" then
-- run/open your script
end if
end clicked

ps : Your links result in this : Safari can’t open the page “http://mossycc.com/Latest/installersdl.zip” because Safari can’t find the server “mossycc.com”.

Thanks! And my website does that. It works for some people and not for others.

----------

Ok, new problem. When I try and run my Script. I get this error.
"Command /usr/bin/osacompile failed with exit code 1"

Here is my Code.
on clicked theObject
if title of theObject = "Update Installers!" then
run shell script "rm -rf ~/MCInstaller/scripts/; mkdir ~/MCInstaller/; mkdir ~/MCInstaller/scripts/; cd ~/MCInstaller/scripts/; curl -O http://mossycc.com/Latest/installers.zip; unzip installers.zip -d ~/MCInstaller/scripts/; rm -rf ~/MCInstaller/scripts/__MACOSX/; rm -f ~/MCInstaller/scripts/installers.zip"
end if
end clicked

Is it because I included the tilde (~) in my Shell Script? I was going to try, but I didn't know what would replace it. Which is why I was going to try and make them as Workflows. But I didn't know how to open them from within the App.

Eg. I have a Workflow/Script in my Resources folder of the App. But when I drag the file into the Code. It links to it as though I was pulling it in from the Finder.

kryten2
May 7, 2012, 08:54 AM
I've only made some very simple little apps in Xcode 3 myself and barely scratched the surface of Applescript. I think your run shell script causes the error, you can run .scpt files but not run shell script. Try this line in Script Editor and check if things are removed, folders created, curl line works etc. If it works you can adjust your code.

do shell script "rm -rf ~/MCInstaller/scripts/; mkdir -p ~/MCInstaller/scripts; cd ~/MCInstaller/scripts/; curl -O http://mossycc.com/Latest/installers.zip; unzip installers.zip -d ~/MCInstaller/scripts/; rm -rf ~/MCInstaller/scripts/__MACOSX/; rm -f ~/MCInstaller/scripts/installers.zip"

The two mkdir lines can be replaced by one by using the -p option. The tilde (~) points to your home directory eg. /Users/username. You can run workflows with this code :

-- change line below to where you saved your .workflow
set workflowpath to "Macintosh HD:Users:martin:Desktop:Example.workflow"
set qtdworkflowpath to quoted form of (Posix path of workflowpath)
set command to "/usr/bin/automator -v " & qtdworkflowpath
set output to do shell script command

Red Menace
May 7, 2012, 10:30 AM
I am not able to access your project to look, but on clicked theObject is an AppleScript Studio handler, which will result in a compile error when building the project if you are using current versions of Xcode with AppleScriptObjC (AppleScript Studio is deprecated as of Snow Leopard).

What OS/Xcode versions are you using? Can you post a smaller example or use a different host that is reliable?