Skip navigation

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

636 Views 12 Replies Latest reply: Jan 9, 2013 5:19 PM by MacOSXNoob RSS
MacOSXNoob Calculating status...
Currently Being Moderated
Jan 7, 2013 5:16 PM

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/, 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)
  • Frank Caggiano Level 7 Level 7 (22,745 points)

    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 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

  • Frank Caggiano Level 7 Level 7 (22,745 points)

    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

  • Frank Caggiano Level 7 Level 7 (22,745 points)

    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 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.

  • Frank Caggiano Level 7 Level 7 (22,745 points)

    If you have the Xcode/Objective-C Applescript part worked out I woul suggest you satrt a need thread dealing soely with any Applescript probelms you are having.



  • red_menace Level 6 Level 6 (14,275 points)

    If you use an alias, the reference remains valid even if you move or rename the file item.

  • red_menace Level 6 Level 6 (14,275 points)

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

         set theDupe2 to (duplicate FullTrashIcon) as alias


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

         set thePath to path to resource "trashfull.png" -- alias

    or the ASObjC way, using the NSBundle class:

         set thePath to current 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.

  • red_menace Level 6 Level 6 (14,275 points)

    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:


    set FullTrashIcon to (choose file)

    tell application "Finder"

      set theDupe2 to (duplicate FullTrashIcon) as alias

      set the name of theDupe2 to "trashfull.png"

      move theDupe2 to desktop

    end tell


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


More Like This

  • Retrieving data ...

Bookmarked By (0)


  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.