How to drive Interface Builder with AppleScript? - macos

I want to programmatically create NIB (or XIB) resource files - like resource import tool. Making XIB file manually is not impossible, it is XML-based file, but there are too many unspecified items.
So, I'd like to use AppleScript to drive IB itself and create the resources with it, but I fail to do so - I can't create any new items and it keeps reporting that it cannot add this object to that container. Does anybody have any experience with that, or some good example that I can use as a starting point?
Thanks.

I don't think Interface Builder is scriptable, but perhaps you could have an script which writes a file with the generic IBFile contents and then just change around some vars.

Related

Open file with app as duplicate

The idea is that I have a template of a file that needs to be opened but it should behave as if only the contents of the file were opened instead of the file itself.
The difference for the user should be, that he needs to select a place to save the file to instead of just overwriting the file that was opened.
Similar behaviour can be seen in the Preview app. When duplicating a function Preview will open the same file in a new window. Upon saving the file the user needs to specify where to save it to.
As far as I can see NSWorkspace does not support such behaviour out of the box. Does anybody know a workaround for that? I'd appreciate it!
EDIT
In my case I don't know where the user wants to save the file to when he or she is done with it. Currently I am only copying the file to a hidden folder in the user's home directory and then I open the copy so that the original file can not be overwritten.
The resulting behaviour is:
- the user does not see where the file is located
- upon saving and closing the application that the file was edited in the user will not find the file ever again.
Workaround: I guess for now I will ask the user where she wants to save it before opening it, which seems kind of redundant to me as it could very well be, that she will not want to save it. Hopefully I will find a better solution soon.
You may be able to achieve this by sending an "open contents" ('ocon'/kAEOpenContents) Apple Event to the target app. The easiest way is probably to use the Scripting Bridge.
The normal way to use the Scripting Bridge requires that you know in advance which app you want to target and generate an Objective-C header from its scripting interface definition. However, you should be able to use it "raw". For example, something like this:
SBApplication *app = [SBApplication applicationWith...:...]; // there are method to take a PID, a bundle ID, or a URL
[app activate];
NSAppleEventDescriptor *desc = [NSAppleEventDescriptor descriptorWithString:#"foobar"];
[app sendEvent:kCoreEventClass id:kAEOpenContents parameters:keyDirectObject, desc, nil];
The NSAppleEventDescriptor object is the contents payload, in this case the string "foobar". You can use other methods to create different types of payloads. If you use the generic one and need a descriptor type, you can look in the headers in /System/Library/Frameworks/CoreServices.framework/Frameworks/AE.framework/Headers (e.g. AEDataModel.h or AERegistry.h).

Mac OSX: How to associate a directory as bundle

I am writing an app for Maverick.
The app creates a folder under /user/document, named "folder.db".
All the user related files will be in a folder "folder.db".
I would like to associate my app with "folder.db" directly, so that clicking on it would open my app and not the Finder.
How to achieve that?
Note: I tried to play with the UTI settings in xcode but not luck...
First .db is generally used for databases. So probably not a good idea. What you are looking for is a package or bundle in Cocoa terms. In Cocoa you want to look for the fileWrapper methods. Those create package/bundle files that are folders with a special flag bit set to make it act like an opaque file in Finder
You might want to study NSWorkSpace, NSFileManager, NSBundle, NSDocument and NSOpenPanel and NSSavePanel.
Those will get you on the path.

import multiple files in the same type in sketchup ruby api

I am a beginer with ruby and sketchup.I need to select and import multiple files at the same time when open a dialog for importing. I used a class, which is inherited from Importer interface of SketchUp . But if i want to import multiple file, it means that i have to open importer dialog many time for doing that. It is inconvenience.
After importing, it is return all the paths of all file i have imported .Do you have any idea for implementing that?
Thanks you so much !
Unfortunately the Ruby API doesn't implement any API to select multiple files in a file dialog.
Further more, if you use the Importer class you are stuck with the file dialog it displays. It's single select only.
If you know all files in the folder should be read you should let the user pick a single file, then extract the path from that and read all the files from that directory.
If you drop the Importer class you can craft your own alternative. The best would then to create a Ruby C Extension that calls the OS API to display a multi-select dialog.
Alternatively, you can create a WebDialog that display the files and let the user pick multiple files. But that means you'll have to create all the UI from scratch and it'll not lok like the native OS file dialogs.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/webdialog.php
https://github.com/thomthom/sketchup-webdialogs-the-lost-manual/wiki
If you are making a Windows only plugin you can make use of the drag and drop feature of HTML5. Though this also has drawbacks of requiring the user to have a recent IE version. (OSX hides the WebDialogs when SU isn't active - so you cannot use it as a drop target when you drag files from Finder.)
I made a proof of concept a while back: https://github.com/thomthom/DropZone

how to get the .tsr file in QTP

We all know that the .tsr file stores the information of the object repository, and We can load the file to an ObjectRepositoryUtil Object in VBS, then we can do a lot through this object.
But how can I capture all the widgets in a window and stores into the .tsr file using VBS?
I mean when we do the following in the QTP GUI:
Resources->Object Repository Manager->Object->Add Object->
"CLICK THE WINDOW WE WANT TO CAPTURE"->File->Save
we actually get the .tsr file of the window and all its components we want to capture.
But how can I do this in VBS, does it have any API?
I look up the document called ObjectRepositoryUtil and find the method GetAllObjects, but it is just not the same thing.
Could anyone solve my problem ? I would really appreciate it.
Thank you.
I'm not sure why you want to automate creating an object repository. Usually object repositories are created once and then used for creating tests.
Are you familiar with QTP's Navigate and Learn feature, it allows adding all objects from an application while interacting with the application.
If you are looking for a tool or code that can actually mimic the object capturing capability of QTP, outside of QTP - then no such tool/code is available as of now. However code can be written to retrieve the object properties of an application and that I assume you are aware of.

File extension icon on Mac

My application uses new proprietary file formats with extensions never been used before. I would like to associate specific icons to display my files in finder with nice iconography. As far as I know LaunchService is responsible to handle all these data, however I'm confused where, when and how shall I create associations.
Which entries I have to add to plist?
Where I need to actually register this extension - during installation? Is there any script for this?
Add a CFBundleDocumentTypes key to your plist, see
Storing Document Types Information in the Application's Property List

Resources