Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScriptObjC app with check marks, asking for files, and moving the files?

I am fairly familiar with AppleScript, but I just downloaded Xcode, and I am trying to make a simple app, but I am completely lost.

What I am making is an app where it asks for icons for Finder, Empty Trash, and Full Trash. I have three check boxes, "Finder," "Trash Empty," and "Trash Full." Whichever are checked, when you click the "Change my Icons!" button, it will ask for the appropriate icons, and move them to: /System/Library/CoreServices/Dock.app/Contents/Resources, then run the Terminal command: killall Dock. I have the appearance set up, but I am clueless on how to match the buttons to the command, and how to make a variable out of each check mark.


Thanks So much!

MacBook Pro, OS X Mountain Lion (10.8.2)

Posted on Jan 7, 2013 5:16 PM

Reply
Question marked as Best reply

Posted on Jan 7, 2013 5:49 PM

That's a lot to try and take in in one shot. Xcode ifself will take you a while to get comfortable with if you've never used it before.


There are some good tutorials out there and a few books worth getting. Plus Apples documentation is pretty good on this.


Here is a link to a tutorial http://macscripter.net/viewtopic.php?id=30274 that should get you started. It's sort of an Hello World app. It will show you how to attach GUI elements and Applescript objects.


One thing to be aware of. Xcode is a real moving target. A lot of sites and books will be out of date so keep that in mind if something you're trying isn;t working like the site or book days it should.


good luck

12 replies
Question marked as Best reply

Jan 7, 2013 5:49 PM in response to MacOSXNoob

That's a lot to try and take in in one shot. Xcode ifself will take you a while to get comfortable with if you've never used it before.


There are some good tutorials out there and a few books worth getting. Plus Apples documentation is pretty good on this.


Here is a link to a tutorial http://macscripter.net/viewtopic.php?id=30274 that should get you started. It's sort of an Hello World app. It will show you how to attach GUI elements and Applescript objects.


One thing to be aware of. Xcode is a real moving target. A lot of sites and books will be out of date so keep that in mind if something you're trying isn;t working like the site or book days it should.


good luck

Jan 7, 2013 5:58 PM in response to MacOSXNoob

Looking over that tutorial it is a bit out of date but the main points it is doing still hold. Specifically it looks like the Interface builder is a older version then what you have. Now it all opens in one app it use to be multiple apps (xcode editor and interface builder were separate, now they are one).


One book that really help me get started is Learn AppleScript by Apress Not only is it a great AppleScript tutorial and reference but it has a great section on getting started with AppleScript and Objective-C


good luck

Jan 7, 2013 10:49 PM in response to Frank Caggiano

So... would this work:

on ChangeFullTrashIconPushed_(sender)

set FullTrashIcon to (choose file with prompt "Choose a PNG icon to use for your Full Trash icon:" of type {"PNG"} without invisibles)

set theFile to "Macintosh HD:System:Library:CoreServices:Dock.app:Contents:Resources:trashfull.png"

set qpp to quoted form of POSIX path of theFile

do shell script "zip " & qpp & ".zip " & qpp

tellapplication"Finder"

set theDupe2 to duplicate FullTrashIcon

set the name of theDupe2 to "trashfull.png"

move theDupe2 to"Macintosh HD:System:Library:CoreServices:Dock.app:Contents:Resources"with replacing

end tell

do shell script "killall Dock"

end ChangeFullTrashIconPushed_


then I control-dragged a button to that script, and did a similar thing with buttons "Change Finder Icon" and "Change Empty Trash Icon" Now I have a didderent problem. When I try to run it, I get this error:

Command /usr/bin/osacompile failed with exit code 1

What does that mean? I sort of messed up with creating a new project of the same thing and not replacing the old one due to a misspelling, so I renamed it in Xcode, and I don't know if that is related, but I also heard in reviews that simulator doesn't work well. How do I fix it? and did I do the first part right?


Thanks so much

Jan 8, 2013 5:19 AM in response to MacOSXNoob

With Xcode the way the connections are made and how the property tags are wrriten are very important it is hard to look at a piece of code like you posted and coment on it one way or the other.


Two things, the compile error should have a line number telling you where the error occured. Turn on show line numbers for the code editor and you'll at least know where the error is happening. The part of the message you posted tells us nothing.


Second I'd really suggest you start with soemthing simpler. Do the tutorial I linked to above to at least get a feel for how all this go together. Just a button and a text field to see ow the connections are made is a good place to start.


I can say that

on ChangeFullTrashIconPushed_(sender)

appears correct as far as it goes. But how it is declared and how it is conected to the window are just as important.


If you want to use the code you wrote above then trash everything between the

on ChangeFullTrashIconPushed_(sender)

and

end


and replace it with

display dialog "MY button was pushed"


and get this to work. Once you have that you at least know your GUI is working then you can add the other code back in.

Jan 8, 2013 4:54 PM in response to Frank Caggiano

I delete the old ones and started fresh. Now, I have a script problem.

when I run the script I showed before, but without the compressing part (I decided to add a "Restore" button instead of archiving), I get the message: Finder got an error: Can’t get document file "1357712224_Finder copy.png" of folder "Downloads" of folder "milodarling" of folder "Users" of startup disk.

I understand that this is because it is looking for the original name of theDupe2, which no longer exists because the script renamed it. How do I move the newly named file to the desired folder?


Thank you

Jan 9, 2013 3:41 PM in response to red_menace

How do I make this duplicate variable an alias? I cannot think of another way to identify it.

Also, how do I access the Resources folder in applescript with Xcode? The normal applescript I've used in applescript apps:


set OriginalFinderIcon to ((path to me as text) & "Contents:Resources:finder.png")

tell application "Finder"

duplicate OriginalFinderIcon to "Macintosh HD:System:Library:CoreServices:Dock.app:Contents:Resources:" with replacing

end tell


This script is not working with my Xcode app.

I have the original finder, trashempty, and trashfull files in there, and would like a button that copies those files to the correct folder when the "Restore _____ Icon" button is pushed


Thanks

Jan 9, 2013 4:09 PM in response to MacOSXNoob

To get an alias of the duplicate file, you can just coerce the Finder reference to an alias, for example

settheDupe2to (duplicateFullTrashIcon) asalias


You can access items in the Resources folder of the application bundle the regular way:

setthePathtopath to resource"trashfull.png"-- alias

or the ASObjC way, using the NSBundle class:

setthePathtocurrent application's NSBundle's mainBundle's pathForResource_ofType_("trashfull", "png") -- POSIX


edit: you can't use path to me in ASObjC, use the above instead.

Jan 9, 2013 4:34 PM in response to red_menace

Thank you so much! The resource script worked! But the duplicate is getting another error:

Can’t make alias "Macintosh HD:Users:milodarling:Downloads:cab copy.png" into type reference.

"cab copy.png" was the file I chose to test the script. Applescript is having an error duplicating that file.

What do I do to fix it?

If this is too difficult, or you can't figure out how to fix it, I can always stick with not duplicating it. The thing is, though, I would prefer to leave the imae that the user chose to be untouched, not to disappear into a system folder where they will likely never find it. If possible, please show me how to fix it.


Your help is very much appreciated

Jan 9, 2013 4:57 PM in response to MacOSXNoob

I'm not having any problems duplicating the file. For testing, you should be able to swap the rename and move statements and it will still work:


setFullTrashIconto (choose file)

tellapplication"Finder"


settheDupe2to (duplicateFullTrashIcon) asalias


setthenameoftheDupe2to"trashfull.png"


movetheDupe2todesktop

endtell


I'm using the desktop here, but you can also use the temporary items folder or a folder in Application Support.

AppleScriptObjC app with check marks, asking for files, and moving the files?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.