Xcode 13 AppleScript framework can't connect UI to Applescript code - xcode

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

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

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

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

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

Related

Xcode Base Internationalization with no Main.storyboard

I'm trying to follow the tips in Apple's I18N and L10N Guide. I have a pre-existing project from which I have (long ago) deleted the Base.lproj folder. Why? Because I have no Main.storyboard or LaunchScreen.xib. Both of those things are handled programmatically.
However I do have a large number of subsidiary storyboards, including a WatchKit Interface.storyboard. When I click the + in the Project (not target) Localizations section, Xcode presents a dialog that lists only the Interface.storyboard file. Not any of the many others.
How can I persuade Xcode to help me localize the other storyboards? Can I do this all manually? As usual, I am sure it is my mental model that needs refinement.
This is an example where configuration yields convention. That is, if you customize your folder hierarchy, Xcode can adapt and implement its naming conventions.
Select storyboard file in left pane (Project navigator)
Click Doc icon (File inspector) in right pane
Click Localize...
This will create a new Base.proj folder inside whatever folder holds the storyboard. If you are like me, you have done lots of folder-factoring. Xcode goes along with this.
Then you go back to the Project Localizations section and click + to add locales. Xcode creates extracts the strings from your storyboard and creates new folders for the corresponding .strings files.

iOS - Using Base localization pane is always empty

In Xcode have added two localizations, German and English. I am following documentation on Apple regarding "Use Base Internationalization" which is obtained by going to the project, clicking Info and pressing on the checkbox.
If I do this, it launches a pane or page which is empty.
IE:
How do I get it to be populated, or otherwise be in a situation to select the relevant resource file?
The answer is to localize your storyboards. Go to storyboard, there is a button called localize. If you do this, the pane is no longer empty.
Check the answer from hassan83 (https://stackoverflow.com/users/1586924/hasan83) in another question. It solved my problems.
https://stackoverflow.com/a/27720065/7017099
"This could happen if Base Internationalization was active before then disabled and files deleted manually.
Create Base.lproj folder in your project folder using the finder.
Move your main story board to it also using the finder.
Fix the reference to it from Xcode.
Remove app from device, clean & build
your project.
All will be back to normal."

Objective-C, Transitioning from .nib to .storyboard

I'm trying to update my application from using .nibs to the more recent .storyboard format on OS X. I'm not exactly sure what the best method of accomplishing this would be.
Currently I have both the old MainMenu.nib and Main.Storyboard in my project. It's easy enough for me to manually copy items from the .nib to the .storyboard, although how do I tell XCode to start using my .storyboard instead of the .nib? Is it possible to use both in the same project? Any suggestions welcomed.
although how do I tell XCode to start using my .storyboard instead of the .nib?
If you no longer want to use MainMenu.nib at all, then you set the NSMainStoryboardFile key in your Info.plist (and delete the NSMainNibFile key). That way, the storyboard file is used at launch.
Info.plist keys are documented here:
https://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
https://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/GeneralPurposeKeys.html

Cannot find the windows outlet for the Object in iOS

I have been working with Xcode 4.2.1, but following some tutorials and videos from the earlier version of Xcode.
As usual I had the problem with the Windows Based Application. I created a empty application for my Windows Based Application project and was following some steps from the same forum of how to add a MainWindow.xib file to my project using this post
There is no .xib file when I create a new "Empty Application" in XCode
I also followed one more post which has some good screenshots:
http://www.trappers.tk/site/2011/06/16/mainwindow-xib/
Now my problem is I cannot ctrl+drag of the window outlet from the App Delegate object to the Window object. The reason is I could not find out the window outlet from tze attributes menu. One can see the screenshot of how it is looking in my xcode:
And below one can see how it should have a windows outlet for the App Delegate.
Is there anything I am missing or left something behind before coming there. I followed the steps exactly as mentioned in the above posts. I tried creating new projects just to make sure Im doing everything correct.
Any information regarding this would be appreciated.
Thanks
Raaks
From your tutorial..
http://www.trappers.tk/site/2011/06/16/mainwindow-xib/
The answer to your problem is Simple(and also this is the way you should do most of the time in future..)
1) Click on File's Owner(In the placeholder section..left to the xib).
2) In the attributes section you will see a window Outlet..
3) Drag window from the attributes section(right click-drag or ctrl-drag.) and drop it on window in Objects window..(left to the xib)

Localizing in Xcode 4 with Localizable.String

I just updated to Xcode 4.
Normally when localizing apps we add "Localizable.String" file to the project, and then navigate to "Get Info" menu and click the "Make It Localized" button.
However, in Xcode 4, there is no "Get Info" menu.
When I try to add a language it only effects the "InfoPlist.String" file (which can only localize the app's name).
How may I add localization to my app in Xcode 4?
It's simple once you understand it.
If you want to accomplish this with Xcode 5.x and iOS 7 or Xcode 6.x and iOS 8, check out "How to localize my app with Xcode 5?" instead.
I liked SNR's link, but his answer was a bit short.
Also, I see that this question is a bit old, and my answer may be different from older versions of Xcode. (I used Xcode v. 4.3.3)
However, i have updated my answer to work with both Xcode 4.3.5 and below + 4.4 and above (and Xcode 5.x and 6.x here: How to localize my app with Xcode 5?).
To begin you should add a new "Strings File" in the iOS Resource category.
Next, create the file as "Localizable.strings".
When the file is created, select it and open File Inspector .
EDIT: Things have changed (a bit) with the new Xcode 4.4, 4.5 (and above) (for iOS 6 support).
If you'r Not using Xcode 4.4 or above, joust skip this step.
{ The Xcode 4.4, 4.5 (and above) way:
Click the "Make localized" button
Now head over to your Main Project page.
And click the "+" button under Localization, and select the languages you want to support.
(I'll select German / Deutsch)
Now a window will appear asking you what files you want to localize, make sure Only the "Localizable.strings" file is selected and click Finish.
}
{ The Xcode 4.3.5 and below way:
Click the "+" button under Localization, and select the languages you want to support.
(I'll select German / Deutsch)
}
.
.
.
.
You should now see that you have two files under the "Localizable.strings" file.
Next, add your localization strings inside both of the localization files.
Now here comes the coding part.
Here i'll simply declare a UILabel and set it's text to the Localizable file string.
Declare:
IBOutlet UILabel *testLabel;
And Inside ViewDidLoad i'll set the text using NSLocalizedString:
[testLabel setText:NSLocalizedString(#"TEST", nil)];
To finish up, just connect our testLabel in "Interface Builder".
Now you should be able to run the Project and see the localized string.
And if you change the language, you should see the localized string change as well.
Select the file you want to localize and klick on the file inspector in the utilities section.
There is a section Localization
You can view the file info (and add localizations) when you select the file and open the "File Inspector" via the main menu's "View" -> "Utilities" -> "File Inspector".
first you need to add new Localizable.string file and select it and go to View" -> "Utilities" -> "File Inspector click on + button to add language in localization section.
also check it XCode 4, Adding localization
the way of Localization in xcode4 has changed! right click the localizable.strings, and to add support for another language, simply click on the ‘+’ in that ‘Localization’ pane on the right.
You can take advanced of the User Defined Runtime Attributes:
http://cupobjc.blogspot.com.es/2014/04/interfaz-builder-localization.html
First define a new category for UILabel:
#import "UILabel+Localized.h"
#implementation UILabel (Localized)
-(void) setTextLocalized:(NSString *)aText{
[self setText:NSLocalizedString(aText, nil)];
}
#end
Then in the interface builder, User Defined Runtime Attributes :
textLocalized String your string to localized
And you don't need to declare the IBOutlet,
and don't need code this in the ViewDidLoad [testLabel setText:NSLocalizedString(#"TEST", nil)];
If you want a dynamic way of switching languages inside your app AND using a Pods based solution check out:
https://github.com/nullic/DPLocalizationManager
Install with: pod 'DPLocalization', '~> 1.2'
It supports the same standard localization files but also uses dynamic linking using User Defined runtime attributes and also inside code such as viewDidLoad.
Some examples in the example project:
self.startup.text = DPLocalizedString(#"TITLE", nil);
self.label.autolocalizationKey = #"LABEL_TEXT";
[self.label updateAutolocalizationArguments:#[#"Hello", #1234567890, [NSDate date]]];
self.autolocalizationKey = #"TITLE";
Download the git project that includes example project showing several examples.
Or you could use TraductoPro to automate this process for you and save a lot oftime. It is a Mac app that integrates well with Xcode.

Resources