Xcode asobjc create "Preferences..." window

I’m looking for instructions/tutorial on how to create the “Preferences…” window (with tabs) in Xcode using asobjc. I know how to use the interface builder but “Preferences…” seems a special thing. I can find same for Swift, etc. but can’t figure out how to translate to and do in asobjc. Bought Shane’s book (2ed when it came out) but couldn’t solve from there.

I just barely know what I’m doing so I suspect I’m missing something obvious. I would greatly appreciate any help.

You could fill an entire chapter of a book with what you’re asking, so a tutorial in a forum would be totally unpractical, especially as there are a number of different approaches you could use.
if you can find tutorials in Swift or ObjectiveC that you think will work for your project, then you could use them as your guide, and ask on the forum about converting the code to ASOC code.

From my own experience and memory of ASOC projects in the past, trying to use xib files and ASOC classes outside of the AppDelegate script, for other windows and their UI can be problematic.
I do most of my projects in Swift these days, so I would be happy to try and help with the code conversion.

You should look into examples of using “NSUserDefaultsController” and or “NSUserDefaults”.
You should find tutorials on the interweb for these Foundation classes.
If you have Shane’s book, then I’m sure there must be something on “NSUserDefaults” in the book.
Or you could create your own preferences solution with plist files loaded and saved in the the Users Application Support Folder.

The preferences window is simply just that, an “NSWindow” with either a toolbar for swapping out views, or a tab controller as the content view of the window.
So you should be able to create a preferences window fairly quickly in Interface Builder.

Sorry I could not help more at this point, but finding a good simple tutorial online would be the best approach, and then post a link to a tutorial for help with the code conversion.

Regards Mark

Hi Mark. Thanks for taking the time. You’ve helped me clarify what I’m after - I can create the Preferences window in Interface Builder, but what I need is a way to connect it the “Preferences…” menu item. I think that’s all. In the video below using Swift at about 3:56 the person uses “PreferencesViewController” as the class of the window (subclass “NSViewController”) and that seems to make that menu-item-to-window connection.

https://youtu.be/raLK95FyQso?t=228

I’ve built the app interface in asobjc and running out of time to learn and switch to Swift (SwiftUI?) - though it sounds like the direction I should be moving.

This is my first app in Xcode and I’m sort of limping my way through just to get a more complicated interface on my AS app.

Thank you for your time. Really.

That video link is showing a project using storyboards for the UI design, you just can’t do that with an ASOC project.
Most of the time you can convert Swift code to ASOC code, but you can’t use SwiftUI techniques with an ASOC project.

Unfortunately with ASOC projects, you have to do it the old fashioned manual way with xib files.
I started a new ASOC project today for the first time in 18 months, just to try and refresh my memory on how your task can be achieved, and I remembered why I converted my ASOC projects over to Swift.
Xcode is the worst AppleScript editor you could use, but is needed for Interface Builder in order to add the UI to ASOC projects.

If I could send you the very basic Xcode project I created, you could see how to achieve the preferences interface you after, but to describe the process I had to go through wold not be practical for a forum posting.

But if I understand your question correctly, to link a menu item to a ASOC class function, you have to click and highlight the “Preferences” menu item, then right click and select the round dot, and drag to the ASOC class object, this could possibly be the AppDelegate blue square object, and then select the function name you want to activate from the list.

And with that description, you can see why a forum is not the best place to describe visual things.

I could post a picture somewhere, but I’m not sure where at this point.

I hope that lame description helps somewhat.

Regards Mark

This image might help you with my lame description of the process.

https://ibb.co/1fMxsfQ

In the image you can see the “Preferences” menu item highlighted, and right clicked, and the round action dot you click and drag from to the AppDelegate blue square object, with the list of functions that can be selected for the menu item, and in this case I selected the bottom displayPreferencesWindow: function.

Hope that helps a bit more.

It’s late here now, so will look in on the forum posting tomorrow.

Regards Mark

Hi Mark. I think I follow everything but can’t get the list of functions that I see in your screen shot. I hate to be a bother but I’d like to take you up on sending me your test basic Xcode project.

Can’t thank you enough for sticking in there with me. After this project I’m moving to Swift!

This is a link to the very basic bare bones skeleton of a ASOC project.
The project does absolutely nothing, other than show you how to display a preferences window from the mainMenu xib file.
It was created in Xcode 11 on Mojave just for you, so if your on a different MacOS version it may not be compatible.

The main parts for you to focus on are the blue square object references created in the mainMenu xib file, and the connections made to the two applescripts in the project, they are the key parts to a simple one xib file approach.

In this skeleton project, you would use the PreferencesManager.applescript to do all of your preferences data storage and saving work, and would have to add the necessary UI object connections from the Preferences window views, to new added functions within this PreferencesManager.applescript file.

If I can expand the simple project further for your better understanding, please let me know.

https://drive.google.com/file/d/1LUGxvb6nZtRkiGq76NUSI6akQVZBRKt9/view?usp=sharing

Sorry I ballsed up the link to the zip file, try downloading it again.

Regards Mark

Yes! Worked beautifully! I don’t know what I could ever do for you in return but if there is something please just ask. Thank you so much Mark. Take care and good night.

Hey No Problem, I like a challenge.
And ASOC in Xcode can be a real challenge.

Just a note for anyone reading this last posting, the image file link will fail to work after one week, because the third party image hosting site has a time limit on their image links.
And the basic Xcode project link is stored in my personal Google Drive account, so at some point I will be removing this file from my account, so this link will also stop working.
Anyone who wants to host these files for future use is welcome to do so.

Regards Mark

Stick with the learning Obj-C
I started in AppleScript then asobjc then into Xcode
I now almost exclusively program in objective c niw!

Don’t waste your time with ObjectiveC.

That’s the language of the past, embrace the future.

Regards Mark

I’ve got to believe there are more people than me who need complex interfaces for their AppleScript apps but there appears to be - and correct me if I’m wrong - no other alternative for complex interfaces than Xcode. There’s no AppleScript Studio or FaceSpan anymore. But finding information about doing the basic stuff like progress bars and setting up Preference windows (in Xcode for AS) was like pulling teeth. If it hadn’t been for the kindness of Mark and Shane I never would have gotten there.

I appreciate the defenders of both asobjc and SwiftUI but give me a book that lays complex interfaces out in Xcode for AS apps and I’m all over it. I don’t want to be an expert on objective-c or Swift for that matter. I just want a professional interface for my AS app and it looks like something that could be presented in a way that even someone like me could utilize.

There, I got that off my chest. Please correct me if I’ve gotten anything wrong.

You’re not wrong. It’s just that not enough people feel the same (or enough to pay for such things).

Thanks Fredrik71 but I’ll need to stick with AS for now.