Skip to content

Mac OS X Hints

Revisiting a PDF page counting script

A couple of years back, I created a bash script to count PDF pages across subfolders. Here's how it looks when run on my folder of Apple manuals:

I use this script on the top-level folder where I save all my Fujitsu ScanSnap iX500 scans. Why? Partly because I'm a geek, and partly because it helps me identify folders I might not need to keep on their own—if there are only a few pages in a folder, I'll generally try to consolidate its contents into another lightly-used folder.

The script I originally wrote worked fine, and still works fine—sort of. When I originally wrote about it, I said…

I feared this would be incredibly slow, but it only took about 40 seconds to traverse a folder structure with about a gigabyte of PDFs in about 1,500 files spread across 160 subfolders, and totalling 5,306 PDF pages.

That was then, this is now: With 12,173 pages of PDFs spread across 4,475 files in 295 folders, the script takes over two minutes to run—155 seconds, to be precise. That's not anywhere near acceptable, so I set out to see if I could improve my script's performance.

In the end, I succeeded—though it was more of a "we succeeded" thing, as my friend James (who uses a very similar scan-and-file setup) and I went back-and-forth with changes over a couple days. The new script takes just over 10 seconds to count pages in the same set of files. (It's even more impressive if the files aren't so spread out—my eBooks/Manuals folder has over 12,000 pages, too, but in just 139 files in 43 folders…the script runs in just over a second.)

Where'd the speed boost come from? One simple change that seems obvious in hindsight, but I was amazed actually worked…

[continue reading…]



Stop Photos from showing the “What’s New” screen on every launch

A while back on Twitter, I complained about always seeing the "What's New?" screen in Photos when I launched the app…

This finally irked me enough that I went looking for an answer…and found one, on only the second entry in my search results.

As the linked answer explains, you can fix the problem by specifying that your Photos library is the System Photo Library, as seen here:

I hadn't specified that my Photos library was the actual System Photo Library, so that button was still active. Once I clicked it, the button grayed out, and on next launch, no more welcome screen!

I think you'll only run into this problem if you (1) migrated an iPhoto library, and (2) kept that iPhoto library on an external drive. In those cases, Photos doesn't set the library as the System Photo Library.

One minor annoyance down, many more to go.



Use less-than-full-day periods in Photos’ Smart Albums

Update: With the passage of time—one calendar day, in this case—I can now say that this hint is wrong. Photos does not respect partial day values. Instead, any value less than one is rounded to zero, so all you can really do is create a Smart Album that finds imports you made during the current calendar day. That is, Date Added - is in the last - 0 - days. This is what I'm using now, as it's better than one day, which actually shows two days (today and yesterday), but it's not as nice as iPhoto's Last Import album.

I've left the hint up, because it's been linked to and tweeted a few times, but it's wrong. Sorry for the lack of testing before I posted it.

[continue reading…]



An in-depth look at moving from iPhoto to Photos

As noted in prior posts, I've recently moved to Photos from iPhoto. So far, it's been a mixed experience. There are some elements of Photos I like, but as of today, those things are outweighed by the things I don't like.

I've vented on a number of the things I dislike on Twitter, but wanted to expand on both the positives and the negatives in more detail. Hence, this "one week in" review (of sorts) of Photos, from the perspective of an experienced iPhoto user.

I've also included some tips for working with and migrating to Photos for those who haven't yet made the move from iPhoto. Finally, if you're still reading, I've listed the key features I'd really like to see come to Photos in a future update.

Note that I am not a great photographer, but I do take a lot of photos—I have over 40,000 photos and a couple thousand video clips in my database. To keep things organized, I use lots of keywords and Smart Albums, so much of my feedback on Photos is concerned with those areas of the program.

First off, my time with Photos hasn't all been bad; there are some things that I really like in Photos…

[continue reading…]



Assign a photo’s Title field based on its filename in Photos

My migration from iPhoto to Photos continues, and today's snafu was my discovery that I couldn't rename files in Photos. This is something I've long done in iPhoto—not for every file, but for ones I'd like to group together using something other than Keywords.

For example, I have a collection of iOS wallpapers, for both the home and lock screens. I name each with either "H_" or "L_" as the start of the filename, which let me create this Smart Album to see them all together:

The inability to rename files isn't critical, in particular because the Title field can be used for the same functionality. But I had a problem: When I migrated, Photos created Titles for some, but not all, of my custom-named images. In particular, it missed all of the iOS wallpapers. I'm not sure if this is because these aren't photos in the traditional sense—they're edited photos I export as PNGs. But whatever the reason, I had hundreds of images that needed a Title that was equal to their Filename.

AppleScript to the rescue…this simple bit of code acts on the selection in Photos, and sets the Title equal to each image's filename.

To use this bit of code, just select the photos you'd like to modify in Photos, then run the script. You can make it a bit easier by saving the script into your user's Library > Scripts > Applications > Photos folder (create as many of those as don't exist). It will then be available in the AppleScript menu in the menu bar, assuming you've enabled that in the AppleScript Editor's preferences.

This saved me literally hours of work, copying and pasting filenames to the Title field. (I was surprised this worked, but it did—you can't change the filename, but you can select and copy it.)

April 28 2019 Update:

In the comments, Daryle W. asked about using this script when there wasn't a modified filename—he'd like to use the filename, but drop the extension. I did a quick bit of searching, and came up with the following, which seemed to work in my limited testing. Please have a good backup before trying this, as it's not nearly as well-tested as my original version.

This should work for any filename extension; I tested with JPG and HEIC and it worked fine. (I originally tried this without using a new variable, but it didn't work—I wasn't able to use the filename in the set cutPosition... line, for example.)



Gain control over Photos’ floating windows

As a recent somewhat-forced convert to Photos, I'm struggling with a number of things—more on that coming in a future post. But one of the tougher adjustments for me is that Photos uses a floating Info window, whereas iPhoto had an embedded info panel.

I keep the Info window open all the time, because I do a lot of work with keywords and location. (I also like to keep the Keywords window open, though this one was also floating in iPhoto.) I resize the iPhoto/Photos window quite often, depending on what I'm doing with other apps—sometimes I want my photos covering the screen, sometimes I don't.

In iPhoto, this isn't an issue (dark-background iPhoto GIF), as the info panel is attached to the main window. In Photos, though, resizing the main window leaves the Info window floating in space (light background Photos GIF).

I don't like the big gap, either visually or operationally, so I wind up moving the Info window next to the newly-resized main window.

There are a few solutions to this problem, the best of which only Apple could provide. They could make the Info window a panel below the photos, or they could make it magnetic so that it would stick to the edge of the Photos window, even as it resizes. I don't suspect we'll see either solution coming from Apple, though.

Instead of waiting for Apple, I used one of Many Tricks' own apps, Moom, which (among its other tricks) has the ability to save window layouts, either within an app or across many apps.

[continue reading…]



Create ‘and/or’ Smart Playlists in Photos

I've recently—begrudgingly, forcibly—migrated from iPhoto to Photos. My iPhone 8 Plus was the main impetus, as Photos supports its new movie and image formats, as well as providing some additional editing features that I can't get in iPhoto. But in my limited time with the new app, my general conclusion is that Photos is not designed for someone who likes to actively manage their photo collection.

I may have more to say about this in a future post, but for now, consider this style of Smart Playlist that I used a lot in iPhoto…

This structure effectively creates an "and and or" logic, where you can have all conditions must be true at the top, yet have an "or" on the keyword: This playlist finds media that have the keyword Midnight or Moonlight (our cats), and are videos.

You simply cannot build this structure in Photos, because the Keyword field is a tokenized pop-up; you can only select one value. If I list the keywords as separate criteria, I wind up with a Smart Playlist that only finds videos with both Moonlight and Midnight. That's not what I want.

This structure is useful whenever you have multiple individual things—kids, lets say—and you want a smart playlist that will find any of your children and any other criteria, like year or camera or whatever.

My first thought at a workaround was to create a Smart Playlist called The Cats, which simply had the two Keywords as "or" criteria. I'd then create a second Smart Playlist that had one criteria set to "Playlist is The Cats" and the other set to find only videos. But Photos won't let you use a Smart Playlist as a criteria (neither will iPhoto, for that matter).

After some fiddling, I came up with an ugly but functional solution: I have to use an extra keyword. Now, any time I add photos of either cat, I have to set two keywords: One with the cat's name, and the other is The Cats. With two keywords on every cat photo, I can use this Smart Playlist to make my "video of either or both cats" Smart Playlist:

I'll have to do the same for our children; each picture of Erica or Kylie will also get a The Kids keyword. It really shouldn't be this hard; Smart Playlists should work as do Finder searches…

Perhaps in Photos 4…or 5…or 6. Sigh.



Bring the Buddy List window back to High Sierra’s Messages

With the release of High Sierra, Apple removed the last vestiges of support for AOL's AIM protocol in Messages: You can no longer login to an AIM account. Yes, this is ancient tech. But it had one feature that a small group of my friends, family and coworkers relied on: The Buddy List window, as seen at right.

The buddy list was a great way to know if someone was available to chat or not—unlike Messages, which simply assumes that it's OK to text someone anytime. You could also customize the away message, to let someone know you're on the phone or you'll be back in 10 minutes or whatever.

As someone who works all day at my desk, the buddy list was a nice way to let friends and coworkers know when it's OK to talk and when I was busy. Also, I could keep these chats exclusive to my Mac, and not have them appear on all my devices, which was a nice benefit (no messages received when I didn't want to receive them).

Alas, High Sierra took that all away…or did it? It did not, as it turns out—the above screenshot was actually taken in High Sierra. The solution? Jabber, another ancient (but open source, unlike AIM; history) messaging protocol.

[continue reading…]



See how long an app has been running

For a recent customer support question, I needed to know how long our app Witch had been running. There are probably many ways to find this out, but I couldn't think of one. A quick web search found the solution, via ps and the etime flag.

You need the process ID (pid), which you can find via ps ax | grep [a]ppname.1That [s]quare brackets around the first letter are there so grep won't find itself—and thus list itself in the output. In my case, Witch runs a background task called witchdaemon, so I did it this way…

$ ps -ax | grep [w]itchd
  774 ??        26:40.73 /Users/robg/Library/PreferencePanes...[trimmed]

With the pid, the command to find that process' uptime is:

$ ps -o etime= -p "774"
11-03:17:12

The elapsed time readout is in the form of dd-hh:mm:ss, so Witch had been running for 11 days and a few hours and minutes. Note that you can combine these steps, getting the process ID and using it in the ps command all at once:

ps -o etime= -p "`ps -ax | grep [a]ppname | cut -d ' ' -f 1`"

It's messy looking, but this form saves time and typing.

June 2018 Addendum: If you add the lstart flag, you can see the exact start date and time for the process. For example:

$ ps -o lstart= -o etime= -p "16866"
Tue Jun  5 05:49:19 2018     09-06:11:25


Create a savable list of 32-bit apps

Apple has announced that 32-bit apps have a limited future on the Mac: They'll be fully supported in this fall's High Sierra release; macOS' 2018 release ("Really High Sierra") will "aggressively warn" users about 32-bit apps, and I would assume, they won't work at all in the 2019 version of macOS ("That Was My Skull!").

But how do you know which apps on your Mac are 32-bit and which are 64-bit? MacObserver has an article that discusses the easy way, via the System Information app—just look in the Software > Applications section, and you'll be able to see a list of apps and a 64-bit Yes/No column. But seeing the list is all you can do—you can't easily save the list for future reference, for instance, nor can you copy/paste the info to another app.

So here's a geekier solution to generate a list of your 32-bit apps, saved into a text file for easy future reference. Open Terminal, and paste this command:

system_profiler SPApplicationsDataType | grep -B 6 -A 2 "(Intel): No" > ~/Desktop/non64bit.txt

This does the same thing as the System Information app, but it dumps the data in text form; the greater-than sign redirects the output to a text file named non64bit.txt, saved to your desktop. The grep is used to show only the 32-bit applications (the full line reads 64-Bit (Intel): No), and the -B and -A options are added to capture the lines before and after that line in the output.

This is probably not overly useful to most people, but I wanted a way to capture the list of apps, as I have over 290 32-bit apps on my machine, and it takes a while to run the System Information report each time.