skip to Main Content

Trying to create an AppleScript executable for MacOS 11.5 using Xcode 13 with AppleScript framework. Right out of the box (no processing on my part), the delegate icon on the IB display does not point to the default AppleScript code. This is clear since the outlet list for the icon claims that the AppDelegate does not have an outlet named theWindow whereas the AppleScript code clearly does. I’ve been trying for days to do a simple Hello World sort of thing and have been completely unable to connect UI elements with the "delegate", especially action elements. Am I missing some configuration step or is this a Xcode 13 bug? In examples I’ve seen on YouTube for creating this for this kind of simple thing the normal Xcode storyboard techniques work as expected (e.g. ctrl drag) but none of them used Xcode 13. Any insight is appreciated.screenshot of IB delegate binding

4

Answers


  1. For future reference, this is starting to pop up on various forums, and appears to be a bug.

    The normal signatures for creating IB outlets and action handlers is not being recognized by the Interface Editor. Existing projects – including the base Xcode templates – will build normally, although the editor shows warnings that outlets/actions don’t exist.

    There isn’t much of a workaround other than creating objects programmatically or going back to an earlier version of Xcode until a fix is issued.

    Update:

    As mentioned in other answers and comments, the IB outlet and action handler connection bug has been fixed in Xcode 14, but the AppleScript application and Automator action templates are no longer included.

    Custom templates can be created (or copied from an earlier version of Xcode from its Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/macOS/Other folder) and placed in a custom templates folder in your user’s Library folder at ~/Library/Developer/Xcode/Templates/. You can name this template folder whatever you want, such as "My Templates", where it will be shown in the template chooser.

    Each template contains a TemplateInfo.plist file with various settings for that template – a complete tutorial is beyond the scope of this topic, but the value for the key "Identifier" in the base dictionary can be used to give your template a custom identifier, such as "com.my.cocoaApplicationAppleScript".

    Login or Signup to reply.
  2. I am using 13.4.1 and the bug is still there.
    I am wondering its its worth trying version 14 beta to see if it has been resolved

    Login or Signup to reply.
  3. Playing around with this a little, I did find a workaround, though it’s not entirely satisfactory. It amounts to editing the xib xml directly. For example, say you have button in the GUI that you’d like to reference in your script. First, create a property in the AppleScript like so:

    property myButton : missing value
    

    Then navigate to the xib file in Xcode, right-click on the xib in the file navigator and choose Open as... → Source Code (the default is "interface Builder XIB Document", which you’ll want to return to later). This will show you the xml that underlies the graphical representation. First, search through the text to find the button in question. It will look something like:

    <window title="Window" ...>
        ...
        <view key="contentView" id="...">
            ...
            <subviews>
                <button ... id="xok-ud-pwL">
                    ...
                </button>
            </subviews>
        </view>
    </window>
    

    You want to get the id from the button, which in this case is "xok-ud-pwL". Then go back up to the top of the xml and look for the AppDelegate entry, which will look like:

    <customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
    

    You’ll want to edit this so that it looks like the following:

    <customObject id="Voe-Tx-rLC" customClass="AppDelegate">
        <connections>
            <outlet property="myButton" destination="xok-ud-pwL" id="gn6-Ea-hra"/>
        </connections>
    </customObject>
    
    • property should be the name of the property in the script
    • destination should be the id value of the button you want to connect
    • id should be a random and unique alphanumeric in 3-2-3 format

    This will create an outlet connection between the property and the GUI element. It will even appear in the pop-up menu for the appDelegate so that you can reconnect it graphically. However, if you delete the connection in IB, Xcode will delete the entry from the xml, so you’ll have to start again from scratch.

    Still buggy, but…

    Login or Signup to reply.
  4. The Release Candidate version of Xcode 14 patch it !

    "Fixed an issue with outlet and action connections to AppleScript-based AppDelegates. (83373726) (FB9643535)"

    But, you can’t create a new project.
    If you could find this old Template directory from an Xcode version < 14, you could add again the template AppleScript App.

    • Quit Xcode

    • Copy source template from version < 14 (I used v12.4):
      /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/macOS/Other/AppleScrip App.xctemplate

    • Copy to the destination folder:
      /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/Project Templates/Other/

    • Restart Xcode

    I think Apple wants to remove AppleScript in next version of MacOS

    Tested on Xcode 14 (14A309) 11 Sept 2022!

    Regards

    Laurent

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search