Chill Cocoa Mac OS
Chill Cocoa Mac OS
The focus of AppleScript in Lion is about bringing the power of AppleScript/Objective-C to the desktop.
Cocoa-AppleScript applets can be executed on computers running either Mac OS X v10.6 (Snow Leopard) or Mac OS X v10.7 (Lion). However, the applets cannot be edited using the AppleScript Editor in Mac OS X v10.6 (Snow Leopard). Properties in Cocoa-AppleScript applets do not retain changed values between executions of the scripts. Its successor Mac OS X 5 also ran on PowerPC when it first launched; it wasn’t until 10.4 that Apple began to switch to Intel processors instead, and 10.6 when PowerPC was finally dropped. Mac OS X was a huge step forward from Mac OS 9 in a number of ways, including preemptive multitasking so that you could actually run multiple things at.
Cocoa-AppleScript Applets. The AppleScript Editor can now create and edit Cocoa-AppleScript applets that provide direct access to the Cocoa frameworks from within their AppleScript code, by using the AppleScript/Objective-C bridge first introduced in Snow Leopard. Accordingly, applets can now display custom interfaces, such as progress windows, programmatically, taking advantage of the standard Cocoa interfaces available in the OS.
Translator 1 2 1 2. Script Templates. New for AppleScript Editor is a template menu, containing a variety of useful script templates, including scripts for creating file processing droplets, Aperture import actions, Mail rule actions, and iChat message responders.
Global Script Application Targets. In addition, the AppleScript Editor now has the ability to globally target a script to a specific application through a new optional “tell application” popup menu. Targeted scripts are excellent for quick development as they do not require the use of tell blocks or using terms clauses.
Cocoa-AppleScript Applets
AppleScript in Mac OS X v10.6 (Snow Leopard) introduced AppleScript/Objective-C and the ability to create AppleScript applications in Xcode that could directly access any part of the Cocoa frameworks. In Mac OS X v10.7 (Lion) the power of AppleScript/Objective-C has been made accessible to scripters with the introduction of Cocoa-AppleScript Applets in the AppleScript Editor.
For the first time, AppleScript can access the Cocoa Foundation and AppKit frameworks directly within applet code, augmenting AppleScript's legendary ability to communicate with and control applications, with Cocoa’s powerful routines for text, number, window, and image manipulation. Combine this new Cocoa integration with AppleScript’s existing access to the UNIX command-line, and you’ve got a fantastic automation powerhouse.
Selecting the Cocoa-AppleScript Applet script template from the AppleScript Editor's New From Template menu.
Cocoa-AppleScript Applet Template
The new Cocoa-AppleScript applet is available as a script template via the AppleScript Editor's New From Template menu. Once selected, you will be prompted to name and save the new applet. This applet accepts most standard AppleScript constructs and code, as well as statements and routines written in AppleScript/Objective-C.
Using AppleScript/Objective-C in an AppleScript applet, to transform text to uppercase.
Caveats
- Although Cocoa-AppleScript applets can be created and edited from within the AppleScript Editor application, they are executed by using a new “Run Application” command in the AppleScript Editor's Script menu that runs applets by launching them. This means that the AppleScript Editor Event and Result panes will not report data during applet execution.
If the standard Run menu item or Run button in the toolbar is used to execute an applet or droplet containing AppleScriptObj-C code, an alert will be displayed informing the user that the script should not be executed within in the AppleScript Editor but should be launched using the Run Application menu option:
(NOTE: The AppleScriptObjC Explorer is a third-party script editor application able to both edit and run AppleScript scripts containing AppleScript/Objective-C code.) - Cocoa-AppleScript applets can be executed on computers running either Mac OS X v10.6 (Snow Leopard) or Mac OS X v10.7 (Lion). However, the applets cannot be edited using the AppleScript Editor in Mac OS X v10.6 (Snow Leopard).
- Properties in Cocoa-AppleScript applets do not retain changed values between executions of the scripts. Use the standard Cocoa User Defaults mechanism to store and retrieve data dynamically.
AppleScript/Objective-C Updates
In Mac OS X Lion, two important changes were made to AppleScript/Objective-C
- AppleScriptObjC can now call plain C functions, in addition to Objective-C. To call a C function, tell 'current application' to execute the function, as in this example:
tell current application to NSRectFill(aRect) - Function parameters of type 'void *' are now handled as if they were of type 'id'. When using such a parameter from AppleScript, you may pass any AppleScript value. Previously, only 'missing value' (equivalent to NULL in C) was allowed.
Script Templates
Finally, an easy way to quickly create your favorite types of scripts! AppleScript Editor in Lion introduces a New from Template menu that contains a variety of useful script templates, including templates for creating Mail rule actions, iChat response scripts, Aperture import actions, and file processing droplets. You can add your own templates by placing the template scripts in the Home > Library > Application Support > Script Editor > Templates folder.
Selecting an iChat template from the AppleScript Editor New from Template menu.
Selecting a template from the menu will prompt you for a name and location for the duplicated template file. Once provided the duplicated script file will open in the AppleScript Editor:
An iChat event handler script for automatically responding to specified buddies.
Global Script Application Targets
For scripters wanting a simple way to target scripts at a particular application, AppleScript Editor in Lion implements a target application menu, beneath the toolbar in a script window, from which you can select the application that will be the target of all the script statements.
https://westdownload.mystrikingly.com/blog/euro-on-macbook-air. This feature can be enabled in the AppleScript Editor editing preference pane by selecting the checkbox titled: Show tell
application pop-up menu
When a script is targeted at a specific application, you don't need to include tell blocks or tell statements for the targeted applicaiton.
This page contains some of my Cocoa/Objective-C source code for fellow Mac OS X developers.
You’re welcome to download and use the source, subject to the License Agreement. It’s assumed that you’re a developer and you know how to make use of the source; I can’t provide support. Happy coding!
Note: all code is unmaintained and unsupported as of 2015.
Chill Cocoa Mac Os X
Donations
Don’t panic: you can use all my code without paying anything! Having said that, a lot of work (and time which I should really be spending with my ever-patient wife) has gone into creating the code below. If my code saves you some time and trouble, and you feel like making a small donation to support my future development efforts, it would be very much appreciated.
You can also take a look at my Amazon Wishlist if you like; it’s always fun to receive a surprise package in the mail. I’ve found that many people prefer this method too.
Feel free to contact me (details here) if you have something else in mind.
If you use some of my code, I want to hear from you!
I’m always interested to hear from developers who have found some of my code useful, and I may link to your app too. If your app uses some of my code, get in touch and let me know about it.
License Agreement
The source code is released under a very flexible license, designed to let you use, modify and/or redistribute the code pretty much as you see fit, whilst providing me with basic protection and credit.
Before downloading any of the source code, please have a look at the Source Code License page. Thanks. :)
Using my code without attribution
Chill Cocoa Mac Os Download
My source code license agreement requires attribution, but I’m aware that some people need a license agreement which does not require attribution. If you’re in that situation, I can help: I’ve set up an online store where you can quickly and easily buy a non-attribution license to my various source code components. The online license store can be found here.
If you have any questions, feel free to contact me.
Source Code
Unless mentioned otherwise, all source code requires Mac OS X 10.2 (Jaguar) or later, and corresponding versions of the Developer Tools to open the projects. Some source may also be suitable for previous versions of Mac OS X.
Any special requirements a project has are mentioned in a note with the project description.
MGWordCounter provides live word-counting (of both the full text and the current selection) for NSTextView on OS X, and UITextView on iOS.
Read more about it here!
Note: this code requires iOS 5.0 or later, or OS X 10.7 Lion or later. In both cases, ARC is required.
MGTileMenu is a customisable tile-based contextual menu component, for iPad, iPhone and iPod touch. It's for iOS 5, and supports ARC, Retina Displays (and non-Retina displays) and VoiceOver accessibility.
Read more about it here!
Note: this code requires the iOS SDK 5.0 or later.
MGSplitViewController is an enhanced replacement for UISplitViewController on the iPad. It allows displaying the master view in either orientation, toggling it with animation, changing the split from horizontal to vertical, dragging the divider, and more.
Read more about it here!
Note: this code requires the iOS SDK 3.2 or later.
Read more about it here!
Note: this code requires the iOS SDK 3.2 or later.
Read more about it here!
Note: this code requires the iOS SDK 3.2 or later.
Read more about it here (and see some videos too)!
Note: this code requires the iOS SDK 3.2 or later.
Read more about it here!
Note: this code requires Mac OS X 10.5 (Leopard).
It uses a delegate system to get its data, is extremely customizable and has a cool Smart Resize feature for when limited horizontal space is available.
Read more about it here!
Note: this code requires Mac OS X 10.5 (Leopard).
MGTemplateEngine is a native Cocoa system for generating text output based on templates and data. It's a close cousin of systems like Smarty, FreeMarker, Django's template language, and other such systems.
It's ideal for Cocoa or iPhone apps needing to generate text output using variable-substitution (with looping and/or conditional logic), including HTML for export or for apps with WebKit-based UIs, invoices or printable templates, mail merge, data export or any number of other things. It's also great (in combination with WebKit) for letting your users create themes/styles for your application.
Read more about it here!
Note: this code requires Mac OS X 10.5 (Leopard) or iPhone OS 2.0.
Note: this code was written on Mac OS X 10.5 (Leopard), and the project requires Xcode 3. The code itself should run just fine on Tiger too.
MGTwitterEngine (on github)
MGTwitterEngine is a class which lets you integrate Twitter support into your Cocoa application, by making use of the Twitter API. The entire API is covered, and appropriate data is returned as simple Cocoa objects (NSArrays, NSDictionarys, NSStrings, NSDates and so on), for very easy integration with your code. Creating a TwitterEngine is as easy as instantiating it, setting your Twitter username and password, and you're done. See this blog post for more.
If you're an iPhone developer, you'll be pleased to know that MGTwitterEngine works on both Mac OS X Leopard and on iPhone/iPod Touch (with the official SDK from Apple).
Note: this code was written and tested on Mac OS X 10.5 (Leopard), and the Xcode file requires Xcode 3.0. The code itself should be fine on Tiger too.
Note: this code requires Mac OS X 10.5 (Leopard) or later.
Note: this project requires Xcode 2.4 and Mac OS X 10.4 (Tiger) or later, but should work on previous versions of Mac OS X if you include the files in your own project.
A simple category on NSView and an accompanying class which together allow you to add 'tracking areas' to your views. Tracking areas are like tracking rectangles but are more robust and effective, and can be configured to track the mouse either at all times, only when the view's app is active, only when the view's window is key, or only when the view is First Responder. You can also choose whether to use the view's visible rect in preference to the rect you pass in. See the example for details.
Fair warning: it uses a polling timer to do its thing, but in my tests it consumes very, very little CPU (0.1% in Activity Monitor), and it will only poll if there are actually some tracking areas set up.
Note: this project requires Xcode 2.4 and Mac OS X 10.4 (Tiger) or later, but if you want to just take the source files and create your own project, it should work right back to Mac OS X 10.2 (Jaguar).
An NSAnimation subclass which provides more desirable behaviour than NSViewAnimation itself in most circumstances; i.e. it animates the views' frames itself in the same thread, leading to visually synchronised movement. Try out the included sample app to see the difference between regular NSViewAnimations and these.
This is based on code by Todd Yandell - thanks, Todd!
Thanks to Joe Goh for a bug-fix which prevented animations from running unless at least one animation-dictionary had an effect specified.
Note: this project requires Xcode 2.1 and Mac OS X 10.4 (Tiger) or later.
A category on NSColor which returns another NSColor for use when drawing label text on top of the receiver. Either white or black is returned, depending on which will have most visual contrast with the receiver's color. In the event of the receiver's colorspace not being converted to RGB, black is returned by default.
Note: this project requires Xcode 2.1 and Mac OS X 10.4 (Tiger) or later.
A category on NSImage allowing you to obtain a resized version of the image to fit an arbitrary size, with a choice of cropping or scaling methods (crop center, crop start, crop end, or scale to fit). Uses high-quality interpolation too.
Here's a screenshot.
Note: this project requires Xcode 2.1 and Mac OS X 10.4 (Tiger) or later.
Here's a screenshot.
Note: this project requires Xcode 2.1 and Mac OS X 10.4 (Tiger) or later.
Here's a screenshot.
Note: this project requires Xcode 2.1 and Mac OS X 10.4 (Tiger) or later.
Here's a screenshot.
Note: this project requires Xcode 2.1 and Mac OS X 10.4 (Tiger) or later.
A simple application which reads iCal's calendars and returns an NSDictionary whose keys are the names of the calendars, and whose values are Calendar objects, with fields 'title' (NSString), 'notes' (NSString), 'color' (NSColor), and both GUID keys used by iCal to keep track of calendars and their source data.
Useful if you need a list of the user's iCal calendars with their names, descriptions and correct colors. This code parses the actual XML property list files which define the calendars; it doesn't use AppleScript, nor require launching iCal.
Note: this project requires Xcode 2.1 and Mac OS X 10.4 (Tiger) or later.
A simple category on NSBezierPath allowing you stroke inside a path, rather than stroking centered on the path.
From an idea by Rainer Brockerhoff.
Here's a screenshot.
Note: this project requires Xcode and Mac OS X 10.3 (Panther) or later.
Here's a screenshot.
Note: this project requires Xcode and Mac OS X 10.3 (Panther) or later. Thanks to Heinrich Giesen for fixing the crasher.
Also includes code to draw colored checkboxes as in iCal, using any color you want!
Here's a screenshot.
Note: this project requires Xcode and Mac OS X 10.3 (Panther) or later.
Shows how to make use of the Mac OS X 10.2 Address Book API. Includes a live-filtering field which locates Address Book entries by forename, surname or company, and demonstrates finding the primary email address for a specified person, as well as their name and picture.
Here's a screenshot (email address purposely obscured for the sake of Mike's privacy!)
Easily implement Find and Replace in your application. Adapted and improved from TextEdit's implementation. Includes both the class and a Nib file containing an appropriate Find panel. Read more about the improvements here.
Here's a screenshot.
Here's a screenshot.
Chill Cocoa Mac Os Catalina
Old slot machine. Ever felt the need to have a window fade out of existence, instead of just closing? Here's how.
Shows how to implement grab-scrolling, like in Preview, Photoshop, Acrobat and more. Includes the two requisite hand-cursors.
Here's a screenshot.
Source for two apps, a client and a server, letting you send full-screen screenshots of your Mac via Rendezvous. This is a modification of Apple's Picture Sharing code.
Not really source code, but just as good! This is a collection of 'MainMenu.nib' files, with the menubars pre-localized into various languages. All items are connected to the proper actions, and several additional resources are included (such as flag graphics, ISO language tables, and more).
Currently, these languages are included: English, French, German, Dutch, Italian, Catalan, Danish, Brazilian Portuguese, Swedish, Finnish, Spanish, Serbian, Japanese and Korean.
Here's a screenshot (this is the Italian nib).
Shows how to create proper snap-to-edge windows or palettes, which snap during the drag (as they should).
A class which gives you icon-buttons with pop-up menus. Configure all kinds of things like whether the menu appears when you click anywhere on the icon or just on the little pop-up arrow, whether the button shows the icon of the last-selected item (like in Photoshop's fly-out tool palette menus), and more.
Here's a screenshot.
Eric Wang's reimplementation of my PopUpImage class (see above), using a subclass of NSPopUpButton. In Eric's own words, the improvements include:
- Reuse of NSPopUpButton's menu-related methods.
- The class has been split into an NSControl/NSCell pair, allowing it to be used within NSTableView, NSMatrix, etc. The core functionality is implemented in a subclass of NSPopUpButtonCell.
- There are also some subtle interface-related improvements.
Ever wanted to find the name (or full path, or icon) of the user's default web brower or email client? Or perhaps their default FTP app, or newsreader? This source shows you how to find the user's chosen default application for any protocol you like.
Here's a screenshot.
A simple Cocoa application, showing how to launch URLs, use the standard About box with a scrolling field of credits, display alert panels, remember window positions, and more. https://bestrload969.weebly.com/spotify-audio-converter-platinum-1-2-2000.html. Useful for developers who are new to Cocoa.
A little app which lets you type a file-extension (like 'doc' or 'html'), and have it show the icon for that file-type (the big, beautiful 128x128 pixels icon). Useful for display purposes.
Here's a screenshot.
Shows you how to choose a font with the standard Font Panel. This little app shows a text field with a font's name and size (like 'LucidaGrande 13'). You can click a button to bring up the Font Panel, and when you choose a new font the text field is updated with the new name and size. Useful if your app needs to choose a default font for something.
Shows how to put images into a table column. We're constantly asked how to do this.
Here's a screenshot.
A little window with a button that doesn't do anything.. unless you click it whilst holding the command, option and control keys. Shows how to detect that those keys are pressed. Useful in all kinds of situations for adding functionality without cluttering up your app's interface.
A cool little app that lets you draw multi-coloured circles and ovals. Shows how to let the user draw shapes with the mouse, how to draw shapes with transparency, and how to let the user hold down the shift key to constrain a shape to be proportional. Just for fun!
Here's a screenshot.
One of my System Services. Source included.
A little Mac OS X application I made a few years ago to sync birthdays from Address Book to iCal, long before iCal was natively able to do that (as it is now). Source included.
Chill Cocoa Mac OS