unix

Latest

  • New command line tools in Mountain Lion manage encryption, sleep and sharing

    by 
    TJ Luoma
    TJ Luoma
    07.30.2012

    For fans of the Terminal, Mountain Lion brought some new command-line utilities. Perhaps the most notable is fdesetup, which Apple explains briefly: "fdesetup allows third-party management tools to enable FileVault, determine encryption status, capture and manage recovery keys, and add users to a FileVault-encrypted system as well as synchronize directory-based user authentication credentials with the local credentials for FileVault access." Apple provides a 'man' page for fdsetup, but if you want more information about it, Rich Trouton at Der Flounder has a very thorough walk-through with a bunch of screenshots and excellent explanations. I'm definitely keeping this one in Pinboard for the inevitable day when I want or need to use fdsetup. I'm also glad to have a more low-level tool for working with FileVault. I had written previously about the "hoops" which were necessary to disable certain users from being able to unlock the computer with FileVault. That process is now a lot easier. But wait, there's more! Patrix over at the Ask Different blog discovered several other new command-line utilities. Some of them are generic Unix utilities (pgrep and pkill) but there are also some OS X specific ones, including: caffeinate – prevent the system from sleeping on behalf of a utility serverinfo – determine server status (is this OS X Server, and, if so, are these things enabled) sharing – create share points for AFP, FTP and SMB services tccutil – manage the privacy database See the original article for more details. Of these, caffeinate seems like the most interesting. I have used Caffeine, the free app from Lighthead Software, to keep my Mac awake at times, but being able to do it in shell scripts could definitely come in handy. Still missing your favorite Unix utility? If Mountain Lion still doesn't have your favorite utility, don't forget you have other options. I have used Rudix when I wanted precompiled binaries, and Homebrew when I want to make my own. Mostly these days I stick with Homebrew, which is regularly updated by a bunch of people, versus Rudix which has a smaller library and seems to be mostly the labor of love of one developer. Others may prefer Fink or MacPorts; I have used both in the past but haven't kept up with them recently. Both of them appear to have been updated for Mountain Lion.

  • KDE 4.8 released, wants to sashay its way into your computer

    by 
    Dante Cesa
    Dante Cesa
    01.26.2012

    Sure, it might not have the marketing flair, nor mindshare of another Linux-based project we know, but that doesn't mean the folks behind KDE haven't been feverishly polishing their take on the perfect desktop environment. That dedication has resulted in version 4.8, which brings forth a bevy of tweaks big and small. Those upgrading will be treated to more layouts in Plasma Workspaces, a new display engine and file-manager, as well as redesigned power management settings. Also on the docket are refinements that improve stability and performance, including groundwork to enable more touch-friendly UIs in the future. Sounds like a win-win to us, so why are you still reading? More info awaits at the source.

  • Linaro member boards get accelerated builds of Android Ice Cream Sandwich

    by 
    Darren Murph
    Darren Murph
    12.23.2011

    Remember Linaro? How could you forget, right? The non-profit engineering organization that formed back at Computex 2010 has been plugging away for over 1.5 years now, and its most recent development involves everyone's fav-o-rite build of Android: Ice Cream Sandwich. The company has just released ICS builds supporting accelerated graphics on two of its member's low cost development boards: the Samsung Origen and ST-Ericsson Snowball. The outfit already displayed videos of Android 4.0.1 running on TI's PandaBoard and Freescale's i.MX53, and the accelerated graphics support that has been made available today makes use of the ARM Mali-400 processor. For those unaware, developers are able to create optimized Linux-based devices with the support of Linaro, and if you're in one of those member groups, you'll also enjoy DS-5 with Gator and libjpeg-turbo support. Head on past the break for a smattering of videos.

  • OpenBSD 5.0 offers more hardware compatibility, less bugs

    by 
    Mat Smith
    Mat Smith
    11.03.2011

    Fans of the Unix-based OpenBSD can crack open a bottle of their favorite open-sourced champers because the operating system has launched version five-point-oh. More evolutionary than revolutionary, this version has been given plenty of nudges in the right direction, with broader hardware support, OpenSSH 5.8 and improved network capabilities. The full change log also includes a plethora of stability improvements and bug fixes too. The volunteer-run OS can now be grabbed from OpenBSD's FTP servers or as a paid-for CD set if you're feeling a little noughties.

  • Dennis Ritchie, pioneer of C programming language and Unix, reported dead at age 70

    by 
    Amar Toor
    Amar Toor
    10.13.2011

    We're getting reports today that Dennis Ritchie, the man who created the C programming language and spearheaded the development of Unix, has died at the age of 70. The sad news was first reported by Rob Pike, a Google engineer and former colleague of Ritchie's, who confirmed via Google+ that the computer scientist passed away over the weekend, after a long battle with an unspecified illness. Ritchie's illustrious career began in 1967, when he joined Bell Labs just one year before receiving a PhD in physics from Harvard University. It didn't take long, however, for the Bronxville, NY native to have a major impact upon computer science. In 1969, he helped develop the Unix operating system alongside Ken Thompson, Brian Kernighan and other Bell colleagues. At around the same time, he began laying the groundwork for what would become the C programming language -- a framework he and co-author Kernighan would later explain in their seminal 1978 book, The C Programming Language. Ritchie went on to earn several awards on the strength of these accomplishments, including the Turing Award in 1983, election to the National Academy of Engineering in 1988, and the National Medal of Technology in 1999. The precise circumstances surrounding his death are unclear at the moment, though news of his passing has already elicited an outpouring of tributes and remembrance for the man known to many as dmr (his e-mail address at Bell Labs). "He was a quiet and mostly private man," Pike wrote his brief post, "but he was also my friend, colleague, and collaborator, and the world has lost a truly great mind."

  • Daily Mac App: GeekTool

    by 
    Megan Lavey-Heaton
    Megan Lavey-Heaton
    09.14.2011

    GeekTool was released as a free download on the Mac App Store a few weeks ago, and it's remained at the top of the download chart since. It's been around for years, and we've featured it a couple of times on TUAW, but the MAS release allows it to reach a new audience. Unlike the GeekTool of yore, the MAS version is not a preference pane, but a separate app. It allows users to display various information on their desktops via three plug-ins: file, shell and image. These are referred to as geeklets and can be used as follows: File: It displays live content from any file. It's mostly used to monitor system or application activity. Shell: This displays the output of any Unix shell command and is the root of a lot of the customizations in the program. Image: Originally developed to display monitoring graphs, it's also used for image customization. As the product description warns, this isn't for general Mac users, but those who are comfortable with Unix and shell commands. Drag one of the plug-ins to the desktop, then customize it for your personal use. There's a lot of scripts to choose from out there. This piece from Lifehacker will help get you started and Mac OS X Tips has a comprehensive list of geeklets. You can use GeekTool to monitor everything from time and date wherever you want to pulling your RSS feed and displaying the album cover of your current iTunes track. While it's not for the brand-new Mac user, or for the faint of heart, GeekTool is good to see if you're interested in learning more about the underpinnings of your Mac.

  • Robert Morris, man who helped develop Unix, dies at 78

    by 
    Amar Toor
    Amar Toor
    07.01.2011

    We have some somber news to bring you this morning: Robert Morris, the cryptographer who helped create Unix, has died at the age of 78. Morris began his work on the groundbreaking OS back in 1970 at AT&T's Bell Laboratories, where he played a major role in developing Unix's math library, password structure and encryption functions. His cryptographic exploration continued into the late 1970s, when he began writing a paper on an early encryption tool from Germany. But the paper would never see the light of day, thanks to a request from the NSA, which was concerned about potential security ramifications. Instead, the agency brought Morris on board as a computer security expert in 1986. Much of what he did for Uncle Sam remains classified, though he was involved in internet surveillance projects and cyber warfare -- including what might have been America's first cyberattack in 1991, when the US crippled Saddam Hussein's control capabilities during the first Gulf War. Morris stayed with the NSA until 1994, when he retired to New Hampshire. He's survived by his wife, three children and one, massive digital fingerprint. [Image courtesy of the New York Times]

  • Five Dropbox tips for Mac Unix nerds

    by 
    TJ Luoma
    TJ Luoma
    12.14.2010

    Dropbox is already a very powerful utility for Mac OS X, but if you're knowledgable in Unix, you can make it even better. Here are five ways that you can use Unix to get more out of Dropbox. 1. I wanted to update my copy of the HTML processing tool Tidy today. I was happy to find instructions for building Tidy under Snow Leopard, but it also reminded me of another way that I've been using Dropbox for some time now. If you compile and install Unix utilities on your own instead of using MacPorts, Fink or Rudix, you will most often be asked where you want to install these utilities to. Normally the answer is /usr/local/, and you would use ./configure –prefix=/usr/local. I became frustrated with installing programs to /usr/local/ because I use two or three different Macs, and I would inevitably find that I was trying to use a program on a computer where it wasn't installed. I'd have to find it, download it, configure it, compile it and install it before I could actually do whatever it was that I wanted to do.

  • Rudix, a lightweight way to add new Unix utilities

    by 
    TJ Luoma
    TJ Luoma
    05.04.2010

    Rudix offers a collection of Unix utilities which do not come with OS X by default. When setting up a new Mac I always install these Unix utilities: wget, ncftp, lynx with SSL support, and the GNU Core Utilities. I compile them manually whenever possible, despite options like MacPorts or Fink. I don't need everything that MacPorts and Fink offer, and installing them always felt like overkill -9 (that's a commandline joke, kids). Generally they try to mimic the commandline syntax of either Linux or FreeBSD, neither of which I have used extensively. Although Rudix offers a giant 361MB DMG with all of the packages includes, I recommend only installing what you need. You can find each program with its own OS X .pkg installer. These pkgs install to the traditional location of /usr/local/ (something both MacPorts and Fink avoid, a side effect of the volume of software they are designed to install, as well as a difference in approach).

  • SDK devsugar: Re-signing applications

    by 
    Erica Sadun
    Erica Sadun
    02.09.2010

    TUAW's devsugar series helps introduce developers to tools and tricks that they might not yet be familiar with. Today's tip centers on signing already-compiled and already-signed applications with a new custom signature. A while back, I posted about a way to sign already-compiled applications with your personal credentials in order to better allow developer-to-developer distribution. By re-signing an application, it allows you to install it on any of the devices you have registered to your account at Apple without having to go through the fuss and bother of normal ad-hoc distribution. In addition, it makes it easier to develop applications on a contractor's machines, to ship them to a client, and then have them signed and shipped to App Store using the client's identity. A basic command-line solution is as follows. It calls codesign (found in /usr/bin) to sign the application, using the default keychain item that matches "iPhone Developer". It's a handy script, especially for informal beta distributions. #! /bin/bash export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate codesign -f -s "iPhone Developer" $1 There are, however, several problems with this approach. First, it assumes you only want to sign with development (typically "Debug build") credentials. That's not going to work if you need to re-sign for distribution. (Solution? Change iPhone Developer to iPhone Distribution). Second, it assumes you only have one developer or distribution profile in your keychain. (Solution? Change iPhone Developer, for example, to iPhone Developer: Company Name to exactly match just one keychain entry.) Third, it assumes the person doing the re-signing knows how to use a command line. For that, the solution is a little more complicated. Recently, this topic came up on a developer e-mail list that I moderate: how do you make it easier for a non-technical client to re-sign an application, normally for distribution. As a solution, I put forth the proposal that one could embed the above shell script behavior into an AppleScript droplet. After consulting with a few colleagues, and gathering their requirements, I decided to give the project a try. I built an AppleScript application that signs any application dropped onto it. You can find a working copy of the application at my website. App Signer iterates through any apps dropped onto it, checks to ensure whether each file (or bundle, really) ends with an ".app" extension, and then attempts to sign those files using /usr/bin/codesign. Users can choose to sign with Developer credentials, Distribution credentials, or select Other to open a prompt and enter text for keychain disambiguation. (See the screen shot at the top of this post for an example of the disambiguation dialog.) The application displays results for each application, one at a time. Please note the following caveats: I make no attempt to guarantee that the app dropped onto this utility is actually an iPhone app (rather than, say a Macintosh application). When working with on-device keychains, the identity used to sign the application has to match the application id set forth in the Info.plist file for the application, otherwise keychain access will fail. This is a free application. It is offered under the BSD license. Use it at your own risk. Credit always appreciated. The open source github repository for App Signer can be found here. To create the application, open the AppleScript source in Script Editor and choose File > Save As > File Format: Application.

  • Manually schedule Software Update 'the OS X way' with launchd

    by 
    Brett Terpstra
    Brett Terpstra
    01.10.2010

    In response to a Macworld article, TidBits' Chris Pepper elaborated on ways to run Software Update, Apple's means of delivering updates and patches, on your own schedule. Beginning with the fact that Software Update schedules its next update based on the time it's currently being run, setting the time for the next update is as easy as running it manually at the time you want it to be scheduled for in the future. Later, Pepper delves into the command line method of updating, using the softwareupdate tool (which we've talked about on TUAW, too) to run it from Terminal. Taking that a step further, it's suggested that you run the command from cron, a UNIX command for scheduling tasks, to automate the command-line updates. However, while it still works fine and is perfectly capable of the task, cron has technically been deprecated in OS X since Tiger. I thought I'd mention the newfangled "Mac OS X way" of handling scheduled tasks, and demonstrate a little of its flexibility. Launchd is Apple's replacement for several UNIX ways of doing things, including init, rc.d scripts and cron. It provides a uniform, XML configuration method and -- in many cases -- is more secure than the replaced methods. Launchd can trigger applications and scripts at boot time, at intervals or even when a file or the contents of a folder change. It can also make sure a daemon or an application keeps running, with the ability to respawn and throttle it. If that's just a bunch of nerd-speak to you, don't worry, this isn't going to be an overly technical post. You can read more specifics about launchd on Apple's developer site, if you want more geeky goodness.

  • Mac 10.6 comes with license to kill

    by 
    TJ Luoma
    TJ Luoma
    09.03.2009

    The name's Leopard... Snow Leopard... and how I wish it was 10.7 instead of 10.6 so I could extend these hokey James Bond allusions further. That said, it is closer than the truth than you may think. Apple has given Snow Leopard a license to kill... but this doesn't have anything to do with espionage or even spyware (pardon the pun). Instead, it has everything to do with Apple's desire to make the shutdown process faster. One of the systemwide refinements tells us that "Snow Leopard is up to 80 percent faster when shutting down." If you've ever waited impatiently for your Mac notebook to shut down while your flight was boarding or at the end of the day when you are anxious to get home, Apple is looking to reduce that frustration. Towards that end, Snow Leopard allows developers to mark their applications as "clean" or "dirty" -- not that kind of dirty! Here's an example of what "clean" vs "dirty" means in this context: imagine you have been working in Pages, but all of your documents are saved (or maybe you've closed all the documents but Pages is still running). Pages can mark itself "clean" which is similar to saying "I'm ready when you are!" Now imagine that you are working in Pages, and you've saved your file, but after you saved it you made some additional changes. Perhaps you have several documents open and unsaved, or you've got a Preferences dialog open. If you look at the 3 circles in the top-left corner of the window, you'll see that the one of the far left has a hole in the middle which goes away when you save the file. If any of those situations are true, Pages is considered "dirty," the programmatic equivalent of "Just a moment please!" When the user tells the operating system to shutdown (not just sleep), the operating system will look to see which applications are "ready to go" and applications are still looking for their metaphorical keys. The ones that are ready? They get killed, and killed hard. It's like the difference between telling an app to "Quit" versus "Force Quit." If you ask it to Quit, it is going to check to see if it needs to do anything before it does. If you tell it to Force Quit, it's just going to go away. If you are familiar with the Terminal, you may have used 'kill' to stop some process from running. Usually if you want to 'kill' an application nicely, you send 'kill -TERM' ("software termination signal") which says "OK, clean up your things and let's go!" However if you find that something refuses to stop, you might use 'kill -9' which is referred to as SIGKILL, described as "non-catchable" and "non-ignorable." This is like picking up your child and carrying him or her away because it is time to go now with no questions asked. Applications which mark themselves as "clean" are telling the operating system: "You can use 'kill -9'/Force Quit on me without worrying about losing anything." How much longer does "Quit" take compared to "Force Quit"? Maybe only a second or two, maybe a fraction of a second. But if you have a lot of applications running and the majority of them can skip that time, it helps the overall speed of the shutdown. Think of it like this: imagine you had a bunch of family members over and you were trying to get everyone out of the house to go to a restaurant: young kids, a couple of older aunts and uncles, and maybe grampa. You've probably asked something like this: "Does everyone have everything they need? Kids, did you go to the bathroom? Uncle Joe, did you get your coat and hat? Grampa, do you have your sweater in case it's too cold?" Even if everyone says "yes" it took longer than if you said "Let's go" and everyone replied "We're all ready!" Is this a "sexy" feature of our newest cat-themed operating system? Not at all, but it is one of those "little details" that makes life a little easier as a Mac user: a little faster, a little more attention to detail, and exactly the sort of thing Apple promised to pay attention to with Snow Leopard. (Big tip o' the hat to John Siracusa's epic Snow Leopard review at Ars Technica for bringing my attention to this feature. I look forward to John's operating system reviews almost as much as I look forward to the operating systems themselves.) photo via flickr creative commons: danzen

  • Entelligence: Stains on the sleeve of my operating system

    by 
    Michael Gartenberg
    Michael Gartenberg
    08.13.2009

    Entelligence is a column by technology strategist and author Michael Gartenberg, a man whose desire for a delicious cup of coffee and a quality New York bagel is dwarfed only by his passion for tech. In these articles, he'll explore where our industry is and where it's going -- on both micro and macro levels -- with the unique wit and insight only he can provide. I originally started this column on my take on what an Apple tablet might be (I literally dreamed about it and started to write it down when I woke up). I was really into it, which explains why I didn't save it as I wrote. I think you can see where this is going. Like a cartoon character who notices that he's no longer standing on solid ground and suddenly begins to fall, I reached over to save, but was too late. My trusty XP install suddenly blue screened. Muttering just a few choice words, I rebooted, only to blue screen again. No problem, there's always "safe mode." Too bad safe mode blue screened as well. With little hope of getting anything recovered, I gave up, fired up my Mac and started from scratch. It's not the first time this has happened to me, where for some reason or another I've lost work on my computer. I suspect it's happened to a few of you out there too. But this latest bad experience changed my thought process from Apple tablets to what's wrong with the whole PC landscape and today's operating systems.

  • 3.0 firmware release expected at 10am PT/1pm ET, quick Terminal tip to check

    by 
    Erica Sadun
    Erica Sadun
    06.17.2009

    Hey, iPhone 3G owners: Please do not download the 2,1 firmware files listed below. They are for the 3G S and will not work on your phone. Read the whole post for details. The correct firmware for the 3G will start with "iPhone1,2" instead. If you were up all night waiting for the new iPhone OS to arrive, you're in good company -- we were too, until we began getting Twitter reports from users in Hong Kong and Sweden that the local carriers sent out SMS alerts to their customers suggesting when they could download 3.0. Those times both align with a 10 am PT/1 pm ET go time, and that's when we're calling it for now; Engadget concurs. That's why you're still seeing 2.2.1 as the most current version in iTunes; the new version hasn't been released yet. Those with a command-line bent and an inability to wait without doing something can launch Terminal and type in the following every few minutes to see whether 3.0 has launched, rather than repeatedly clicking the Check for Upgrade button in iTunes (note that the up-arrow in Terminal reloads the previous command): curl -s -L http://phobos.apple.com/version |\ grep -i restore |\ grep '_3.' | open -f The results will look something like URLs ending with this: iPhone2,1_3.0_7A341_Restore.ipswiPhone2,1_3.0_7A341_Restore.ipsw The model number indicates which unit has downloadable firmware. As of right now, only the iPhone 3G S firmware has been updated. That's the 2,1 iPhone model. Yes, the 1,2 iPhone 3G model was considered a revision of the first generation 1,1 iPhone as it only had moderate hardware changes. The two iPods are 1,1 and 2,1 for the first and second generation. (No, for those wondering in the comments, you cannot download the 2,1 firmware and install it on your iPhone or iPhone 3G -- it will only work with the 3G S.) To download, copy the URL and paste it into Safari's download window or use any other favorite method to retrieve the firmware. Then hold the Option key and click Update in iTunes. Navigate to the firmware (the ipsw file), select it, and 3.0's good to go. Of course, you can also download directly through iTunes as soon as the update is available.

  • SGI name lives on after $42.5 million sale to Rackable Systems

    by 
    Joseph L. Flatley
    Joseph L. Flatley
    05.12.2009

    As you know, Rackable Systems was originally hoping to acquire the one-time king of the 3D set for $25 million (with some speculating that even that was a bit much), but it looks like the bankruptcy judges had other plans. Now that the dust has settled (and a check has been cut for almost twice the original asking price) it looks like the two companies will finally merge, forming an outfit called... SGI. The newly minted Silicon Graphics International hopes to combine the strong server business of Rackable with the original Silicon Graphics Inc. name (and overseas service contracts), inspiring the same sort of technological alchemy that once brought the iconic brand to the silver screen by way of such fine cinematic fare as First Kid. In addition, SGI plans continued development and support for the existing Silicon Graphics and Rackable product lines. Quite frankly, we really don't care what they do, as long as they bring back the Indigo -- back in the day we would have killed for one of those bad boys.

  • ExpanDrive 2.0 expands to Amazon S3

    by 
    Brett Terpstra
    Brett Terpstra
    04.27.2009

    I had to do some extensive testing before I got too excited, but after a conversation with the developers I'm pleased to announce that ExpanDrive 2.0 is out. We've mentioned it before, but to recap: ExpanDrive allows you to mount remote servers as drives directly accessible in Finder. With a completely rewritten (again) SFTP layer, the existing FTP support and new Amazon S3 (Simple Storage Solution) support, it's even more useful than the last time we mentioned it. One of the developers, Jeff Mancuso, mentioned to me back at the last WWDC that the S3 support was in the works; it's great to see it come to fruition. In my testing, I found that a previously-existing S3 option, JungleDisk, can cause conflicts with ExpanDrive's S3 support. JungleDisk users should note that there are some issues, but they seem to clear up if you create vanilla buckets in your account and use those with ExpanDrive. I personally found that I was willing to give up JungleDisk entirely at this point, preferring this direct-mount with all of the perks, including a contextual menu in Finder for quickly setting public read/write permissions. I can attest to the fact that it's faster, and that the S3 support is working (wonderfully, without JungleDisk). ExpanDrive 2.0 is a $39.95 purchase (well worth it if you deal with remote UNIX systems or S3), and a $19.95 upgrade for existing users. There's a free trial available.

  • SGI to sell itself for just $25m, throw huge sadness party

    by 
    Darren Murph
    Darren Murph
    04.02.2009

    Man, the difference a few years decades makes. In the 90s, Silicon Graphics helped create silver screen mega-hits like Jurassic Park and Terminator 2, and in 1997, its fiscal year sales totaled $3.66 billion. Today, the company's mired in its second bankruptcy, which has occurred just three years after the first. In order to just terminate the dream before it gets any more nightmarish, SGI has announced plans to sell itself to Fremont-based Rackable Systems for a mere $25 million -- and some analysts are even concerned that the suitor here could be sinking its teeth into a sour deal. The agreement still has to be approved by a bankruptcy judge, and of course, there's still a few more inches of red tape to cut through, but we'll be sure to let you know when the fantasy ends and the wake begins.

  • Tweets (and whatever else you want) on the desktop with GeekTool

    by 
    Mike Schramm
    Mike Schramm
    03.10.2009

    Mat posted a while back about the magic of GeekTool -- it's an app that allows you to run Unix scripts and show logs in a good-looking pane right there on your desktop. Mac OS X Tips recently did a post about how to put your iCal events up there using a script called iCalBuddy, but industrious reader Ben G. has taken this even a step further, and sent along a link to a similar script called twitterbuddy, which -- as you may have guessed -- will send your latest tweets to GeekTool.As a result, he's got the desktop you see above -- both tweets and iCal events sitting in a transparent pane on top of his desktop background. It will require a little Terminal tripping, but it's pretty easy to do. Just install and set up GeekTool the way you like it, and then make sure the buddy scripts are installed. From there, you can create a New Entry in GeekTool, and run whatever commands you want. It's incredibly flexible, too, because it'll put any Terminal commands you can throw at it right there on your desktop. If you're looking to fill in some of that unused Desktop space, give it a look.

  • This afternoon, party like it's 1234567890 Unix time

    by 
    Ross Miller
    Ross Miller
    02.13.2009

    Number aficionados, you probably already know what happens today. As of 6:31:30PM ET this afternoon it will officially be 1234567890 Unix time, which started at zero and has been counting seconds since the stroke of midnight on January 1, 1970, not counting leap seconds. We suggest you put on your best watch or other geek chic and enjoy that one fateful second of sequential bliss -- as the story goes, 1234567891, party over, oops, out of time. In case you've got other plans and can't celebrate the milestone, we'll see you December 22, 2282 at 3:13:30PM ET for the merriment of 9876543210. [Via Wired]

  • Revisiting the randomized signature AppleScript, now with API goodness

    by 
    Brett Terpstra
    Brett Terpstra
    02.10.2009

    When I shared an AppleScript last week which created randomized signatures using TextExpander, I promised to revisit it when the iheartquotes.com API started working again. It's working right now, but it seems to go up and down; check this link before you try the script and make sure you get a quote, not an error message. As before, when used with a TextExpander snippet set to the AppleScript type, this script will provide a random quote, this time pulling it from the Internet rather than our own list. The script is essentially the same, so I'm only going to explain the part which changed; visit the previous article for a rundown on the rest: set _date to do shell script ¬ "date +'Sent on %A, %b %d at %l:%M %p'|tr -s ' '" set _quote to "" try set _quote to do shell script "curl -s \\ 'http://www.iheartquotes.com/api/v1/random?source=macintosh&max_lines=4'" set {astid, AppleScript's text item delimiters} ¬ to {AppleScript's text item delimiters, return} set _quote to paragraphs 1 through -3 of _quote as string set AppleScript's text item delimiters to astid end try set _out to " -Brett " & _date & " ________________________________ Brett Terpstra | myemailaddress@mywebsite.com The Unofficial Apple Weblog | http://www.tuaw.com " & _quote return _out The curl call Here's the part which makes this more interesting than it was before: set _quote to do shell script "curl -s \\ 'http://www.iheartquotes.com/api/v1/random?source=macintosh&max_lines=4'" First off, that really should be all one line, but is split here for formatting purposes. You can remove the double backslash (\\) and merge the lines together if you like. What this does is use AppleScript's ability to run shell scripts (Unix commands) to make a curl call to retrieve a response from the iheartquotes API. Note the "try" statement surrounding that section; it will just return our regular signature without the quote if anything goes wrong. If it gets a response, it stores it in a variable (_quote) and then trims off the last line, like this: set {astid, AppleScript's text item delimiters} ¬ to {AppleScript's text item delimiters, return} set _quote to paragraphs 1 through -3 of _quote as string set AppleScript's text item delimiters to astid The first two lines (actually one line) are shorthand for setting "AppleScript's text item delimiters" -- the character that AppleScript uses to separate text items in a block of text -- to the return character and store the current text item delimiter in a variable so we can restore it with the last line. Using the paragraphs command, which automatically uses the return key to separate paragraphs, we turn the quote into a list of paragraphs, starting with the first and ending with the third from last. This is because the last two "paragraphs" are always an empty line and a permalink (even if you use the API's parameters to turn off the permalink). The last part of that line, "as string", is where the text item delimiters come into play, putting the list items back together with a return after each one, reconstructing the original formatting. Note: You could do the same thing by adding |sed -n '$!p' to the end of the do shell script line, right before the last double quote. I suppose you might as well, as long as you're dipping out to the shell anyway ... From there it's the same as before, just building a final output string from the pieces we've created. This method provides a much wider variety of randomized signatures than constructing your own list by making use of a small section of the wide array of data on the interwebs. The use of curl in an AppleScript can open a lot of possibilities, such as posting to Twitter in various ways. or shortening urls on the fly. Have fun.