Convert Applescript to Xcode Project

Discussion in 'Mac Programming' started by omgitssum1, Feb 25, 2014.

  1. omgitssum1 macrumors newbie

    Joined:
    Feb 24, 2009
    #1
    I made a very simple AppleScript app that:
    1. takes clipboard string
    2. calculates the percentage of certain characters in the string (e.g. # of A's and B's in the string) and store this number as a variable
    3. use that variable in another formula and get a numerical result
    4. display that result in a dialog box (along with a button to "recalculate" the formula using a newly copied string)

    What's annoying is that due to the nature of AppleScript, after clicking "recalculate" a new dialog box reappears at the center of the screen instead of remembering the window location.

    So, I want to see if I can convert this into a more native Xcode cocoa project. The thing is, I've never made anything in Obj-C before (meaning I can't write anything, but can read/try to figure out/modify Obj-C code if it is presented to me). I've already layout text field, buttons, and labels Xib file, and have tried to set them up using modified Obj-C code found online (as in rewriting my app in Obj-C), but this is proving to be extremely frustrating with my lack of knowledge.

    Does anyone have any tips or would be willing to guide me? I know there is an Applescript based Cocoa application template in Xcode. Is that what I need? Thanks.
     
  2. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #2
    Hi,

    That's a pretty broad question. There is a lot of merit in learning Objective-C, but it's probably not going to be a quick process. If you're already comfortable with AppleScript and your project is pretty simple then AppleScriptObjC may be enough.

    Make a new Xcode project using the Cocoa-AppleScript project template. You should end up with a bunch of files, one of which is called something like:

    Code:
    XXAppDelegate.applescript
    
    …look for a function called:
    Code:
    applicationWillFinishLaunching_
    and add something like:

    Code:
    display dialog "Hello World"
    …that code will run when the app launches.

    I'm afraid I don't have time to hold your hand through learning ApplescriptObjC or Xcode, but there are many good sources of info around, some of which are:

    http://www.macosxautomation.com/applescript/apps/index.html
    https://developer.apple.com/library/mac/releasenotes/ScriptingAutomation/RN-AppleScriptObjC/

    Good luck!

    Rob
     
  3. omgitssum1 thread starter macrumors newbie

    Joined:
    Feb 24, 2009
    #3
    Thanks superscape!

    I guess there is no way out of learning a new language, since Applescript Obj-C doesn't seem as simple as just plain Applescript. Regardless, thank you for your help!
     
  4. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    There's a bit of a learning curve to going from AppleScript to AppleScriptObjC. It's probably not as hard as you think, don't be discouraged. Once you've got the hang of how to deal with the various Cocoa classes etc then it's not very different at all.

    That said, if you have the time and patience to learn Objective-C then that will be time well spent.
     

Share This Page