Categories
Programming Tools

Playlister

In the past couple months, I’ve had an ongoing series on converting iTunes playlists to text files, with a brief digression into scripting with Swift. While I doubt that I’m entirely done with the topic, I have reached a point where I’m ready enough to do another write-up.
This morning, I made playlister available to the public. It is not a consumer-facing application like my others; it is very much a tool for people who are comfortable with the command line.
In between the previous iteration of this tool and the current, I actually had a version of playlister built and shareable (Chase has that version installed on his Mac, actually) but, before releasing it to the public, I looked at the code and thought “I can do better.”1
So I buckled down and spent some time indulging in my love for API design, and tried some tricks I’ve been wanting to try.
The rewritten version ships with a library, LibPlaylister, that provides the basic ideas — protocols that allow for interacting with the library, playlists, and tracks; conversion to Markdown — as well as some neat new tricks. There’s some hooks for customization, such as the RatingFormatter protocol, and included FiveStarRatingFormatter, and the new LinkStore protocol, which provides a layer of abstraction on the SQLite-based caching of links.2
It was also an excuse to add to my Swift toolbox. I worked with SwiftCLI for a while, and then converted to ArgumentParser when that was released. I’ve done file interactions, and a lightweight database. I’ve learned a lot about Swift Package Manager.3 I learned a bit about XCTest, and figured out how to get it working in GitHub Actions. (And, more interestingly, figured out how to conditionally include frameworks in an SPM package. I wanted the tests running on Linux, but Linux… doesn’t have the iTunesLibrary framework, shockingly.)
I had fun building this, and will probably continue to tweak it. (I mean, it could be fun to get it automatically pulling links from the iTunes Search API, and just asking ‘is this the right link?’ instead of requiring manual entry.4)
For now, though, it’s ready enough to share, and made for a fun write-up and a good way to de-stress by tinkering.


  1. Interesting aside from giving that to Chase: Did you know that macOS has a ‘quarantine’ flag it puts on executables sent via AirDrop? That was some fun googling to figure out. The solution: xattr -d com.apple.quarantine ./playlister 
  2. That caching is definitely the biggest productivity gain of this, as compared to the previous version — now, when I go to write up my monthly playlist, the whole first part of the playlist doesn’t require any interaction at all. 
  3. Coming from working with nom’s package.json format at work, SPM Package.swift files are nice. Like, you can have comments in them! And, more, you can have actual code, so you can do neat stuff like this
  4. Although, at that point, I’d probably wind up writing it up as a SwiftUI app so I can show images. Which… might have been part of the inspiration for making LibPlaylister a separate library. 
Categories
Education

User Testing

I am rather bad at the whole concept of relaxation. I say this as an introduction, because writing this post is my idea of taking a break from putting together the final presentation for my class on user testing.
The course has been interesting overall. I will readily admit that I don’t intend to make a career of user research, but I am glad I’ve had the experience. Research is, after all, critical to design and development both. We can try to stick to the whole “if we asked people what they wanted, they would’ve said ‘a faster horse’” thing, but, shockingly, we actually aren’t omniscient. We aren’t our users.
Throughout the course of the course (and now you can tell my brain is a bit fried, because I’m throwing in wordplay), we’ve used a few different techniques. My favorite so far has been card sorting: it’s easy to explain, quick to do, and works very well for figuring out a sensible way to organize a bunch of stuff.1
I also quite enjoyed the competitive analysis assignment—going through, as best as I could, the entire market for a specific category was a surprisingly fun challenge. It’s also immediately visible how useful it is, from a strategic perspective: at the end of that assignment, I closed out an open project I had where I’d been putting together sketches for a fitness application. While it would’ve been fun to build, it really wouldn’t have had anything truly unique to establish itself in the market, and I’m too much of a Broke Millennial to be able to devote that much time to ‘fun to build.’2
We also did some quantitative and qualitative user testing, which I found interesting, but also served as the main argument for my “I don’t have a career as a researcher ahead of me” stance. Interesting, yes; useful, when done right; surprisingly difficult to do right, absolutely.
The qualitative structure was a bit more forgiving than the quantitative. We used UserTesting.com, which has a well-polished interface for assembling a test, a slightly less well-polished interface for going through a test, and a checkout page that leaked memory at an astonishing rate.34 Those complaints aside, the actual data I got was very helpful—the biggest issue I had with it was because of my own mistake, and the more open nature of the test meant that even that failure helped me sort out the answer to a different question I had.5
Going into the class, I thought I was going to like the quantitative testing more—I majored in computer science, and threw in a minor in math at the end, I’m a Numbers Guy. In execution, though, I wasn’t a fan. Part of this is probably due to the software we used: I was utterly unimpressed with Loop11. Their test assembly and reporting interface felt very Web 2.0, which I always find a bit alarming for an online-only business, and while the test-taking interface was a bit better (hello, Material Design 1.0!) it was unusable in Safari and a privacy disaster waiting to happen everywhere else.67 And for all that trouble, the data I got wasn’t all that useful. Though, a caveat to that: quantitative testing is more appropriate for summative testing, verifying that your completed design/product works as it’s supposed to, and I won’t be in a position to actually do that sort of testing for, oh, months at the earliest. Certainly not in time to use the results for this class, so I misused the technique a little bit in order to have something to work with.
As I said at the start, though I don’t intend to make a career of this, I’m glad to have taken the class—at very least, it means I’ll have that much more respect for the work my colleagues who do make a career of it are doing. And I sincerely doubt that this will be the last time that I do some testing myself; it’s important to do, and I quite like having the data to validate my designs.


  1. You can do it with actual cards, if you have time and are actually in the same place as your participants. If not, you can use online tools. We used OptimalSort, which is available as part of the OptimalWorkshop suite of tools. If that’s the only thing you’re going to do with it, I honestly can’t recommend it, because while it’s a good tool, it is not, on its own, worth the price. (Having seen their pricing structure, am I considering breaking into that market? Only vaguely.) 
  2. But hey, while we’re on the topic, check out some of my apps
  3. I left the tab alone for ten minutes and came back to 30,000 error messages in Safari’s console and about 2 gigabytes of RAM consumed. On their checkout page. C’mon, folks, that’s just embarrassing. 
  4. To be fair, I’ve got a pile of content blockers enabled, and at a quick glance quite a few of the error messages where a result of that. On the other hand, you shouldn’t be throwing that many little privacy-violating scripts at people to start with, and you definitely shouldn’t be doing it so badly
  5. I’m being intentionally vague about what I was actually testing, because it’s something I may yet fully develop, and I don’t talk about things until they’re good and ready. 
  6. I suspect Safari’s refusal to work with it was related to the latter concern; I didn’t dig into what was going wrong, just threw my hands in the air in disgust and installed Firefox. 
  7. As far as I can tell from some cursory inspection of the functionality of their ‘no code’ feature, it works by having your testers install a browser extension that… executes a man-in-the-middle attack, of sorts, on every page they view. When asking people to do the test, I told them to install the extension, do the test, and then immediately uninstall the extension—and that because I didn’t want to try walking people through installing a completely separate browser to do it in, like I did. 
Categories
Programming

Relational Databases

Inspired by a mix of Julia Evans and how much fun I had last time, I threw together another sketchnote on the basics of relational databases.

Relational Databases: How we store data! They model relations between things. Databases have tables, which have rows and columns.  A column has one type of data, like CHAR, VARCHAR, and NVARCHAR for text, INT, BIGINT, FLOAT, and DOUBLE for numbers, BOOL for booleans, and DATETIME for dates and times. Columns can also be nullable, which basically means ‘optional.’ Having a single type of data per column allows databases to be very fast and efficient. Rows are the actual data in the database, and are also referred to as ‘records’ or ‘entries.’ Keys: a table has a column as its primary key. That means that each row has a unique value there, which you can use to identify the row. Kinda like a social security number, or your phone number - it’s uniquely yours! A foreign key is a value that is the primary key of another table. You can use it to reference a row in a different table.
(Obviously I’m skipping over a lot of detail, but as a very quick intro to what a relational database is, I think it works!)
Categories
Education Portfolio

Value-Sensitive Design

The first unit in our course on Advanced Design and Prototyping focused on Value-Sensitive Design, and a couple of the assignments we did as part of it were pretty fun.

The first was to do a sketchnote on the concept itself. I’ll admit, I was a bit skeptical of the concept of sketchnoting – I thought it would be fun, but I didn’t think it would actually be all that useful. In doing it, however, I found that it helped me to coalesce my thoughts a bit – though, admittedly, that may have more to do with the fact that it forced me to go through my typed notes again than the sketchnoting itself. Still, it was a fun way to do that bit of studying, so I think I’ll try to add it to my workflow in the future.

Presented with apologies for my terrible handwriting.

Another activity was to put together a presentation, going through some value-sensitive design processes and presenting our ‘findings.’ Of the available prompts, I chose the one that boiled down to “your team has just been hired to design a photo-sharing application; you’re in charge of the VSD portion. Go.”

Categories
Portfolio Review

Competitive Analysis: Fitness Apps

The second unit in my course on User Experience and Evaluation was on competitive analysis — looking over the competitive landscape in a given marketplace, and using that data to figure out both the low-level design and high-level strategy you should use to effectively compete.

While I considered doing an analysis of the productivity management/to-do-list marketplace (an area on which I have many opinions), I realized that the end result of that analysis would be “the marketplace is saturated, and the ‘table stakes’ level of functionality is prohibitively expensive to achieve.” Not the most exciting result.

Instead, I looked at another area where I’ve gone through a surprising number of apps: fitness tracking. Specifically, workout planning and tracking – I did a previous assignment on how people use the gym, and one of my findings was “hoo boy are there a lot of different systems for planning and tracking a workout.”

After downloading quite a few apps and compiling a rather monstrous spreadsheet, I put together the results into a report, which I’m now posting here.

(Will I be using these findings to develop an app? … No comment.)

For those using screen readers, or who prefer their own reading environment, you can download the full presentation PDF here:

Categories
Review

“Children of the Eighth Day,” or, “but at least nobody cares that the prince is gay”

Don Sakers
I mentioned in my last review that I was reading this omnibus; I didn’t review the short story in the middle, as it seemed a bit too short to be worth the effort, but did enjoy it. And it provided a good introduction to the characters here, eased the transition of skipping forward half a millennium or so.
I’ll start off by saying that I enjoyed “Children of the Eighth Day,” but temper that by saying it wasn’t as good as “Dance for the Ivory Madonna.” It’s more removed — it’s a space opera, and I’m much less familiar with the goings-on of an interstellar empire than I am of the modern world.
The overall flow was interesting — the first half of the book wraps up far more than I thought it would, and the second half has an entirely different set of issues for the characters to confront.
In retrospect, I think the short story leading in to this is not just helpful, but perhaps necessary, to be able to at all follow the events of the first few chapters. Things kick off very quickly, and trying to figure out the context of the Empire and the Family would be a bit much in addition to the actual events of the plot.
Final verdict: I do recommend the omnibus as a whole, but it might be worth reading it out of order — there’s a bit of spoiler effect for “Ivory Madonna,” as historical context, but I don’t think it gives away enough to really ruin the book for you, if you do read it in that order.

Categories
Review

“Dance for the Ivory Madonna,” or, “actually, some of this might work”

Don Sakers
This is… the most fun piece of cyberpunk I’ve read. I was going to add a qualifier to that, but in trying to come up with one, I realized it doesn’t need one; it’s just the best one.
Unlike most cyberpunk, it doesn’t feel dated by the technology. Sure, it’s set in the future, which helps, but it’s set in a future that feels like a reasonable future based on our current technology, not based on the 1980s.
The setting is fascinating: the world map has been severely redrawn, most noticeably by the USA splitting into several pieces, and by the fledgling African Union actually taking off and becoming a (if not the) world power. At the same time, however, those national divides have become less important, with the UN finally taking over global police actions, aided by a technocratic NGO, the Nexus.
The protagonist is a Nexus operative, and as the story goes on you find out he’s veritable royalty — his father a founding member of Umoji, the African economic union, his grandmother the person whose ideas gave birth to the Nexus, and a few other fun surprised along the way. (I won’t spoil any more than that, it truly was fun finding things out as I went.)
Throw in the global economy being run by AIs, a well-explained split between AR and VR, and a space program based on a mix of ion thrusters and orbital velocity cannons paired with gigawatt-laser-pumped-solar-sails, and I am sold on this setting.
I’m interested to read more of this — I’m reading the Worlds Afire omnibus, which includes three books in the series, if I’m remembering correctly. However, the series isn’t just in this one era, it’s apparently operating on a truly enormous scale, so it’s very possible that the events of the next book will be more than a billion years removed from what I just read.
As long as the next is further into the future, though, I can reasonably expect to see at least historical references to the characters here — the results of the plot certainly feel big enough that they’d carry a long ways throughout human history.
If I’ve sold you on this book now, which I rather hope I have, because it’s a delight, you can go grab the omnibus.

Categories
Review

“Please Don’t Tell My Parents You Believe Her,” or, “a much better end than I was expecting”

Richard Roberts
This is another book that I put off reading for a while. I knew going in that it was the last in the series — Roberts’ blog made that pretty clear — and then, shortly after I bought it, his publisher went under (or something? I’m unclear) and seemed to pretty effectively tank any hope for future works in the amazing world he’s built here.1
And that’s what always shines to me about his books: the world-building. Roberts has a gift for showing without telling, and manages to perfect balance explaining a little bit and leaving a bit to the imagination. One of my favorite scenes in “… You Believe Her” was Penny, sitting on a train, watching a couple boys study. It’s just that one of them was using his telekinesis to levitate the book instead of holding it with his hands. And she goes off on a little tangent, thinking about the statistics of superpowers, and we find out that the superheroes and supervillains are the statistical outliers, while there are also sorts of normal people who use their powers to… not wear spandex and beat each other up. To study. To do their jobs. To make music, or build cool computers.
That’s what I love about the series. It’s a great big world, and Roberts wants to follow the same “but what about-“ trail of implications that I always do.
It’s also hilarious, if my gushing over the world building hasn’t sold you. This book introduces Gerty the Animatronic Goat, who I described to my friend as “the single best comic-relief character I’ve ever read.” It’s silly, and wholesome, and my jaw is a little sore from how much I smiled while I was reading the book.
And the thing is, Gerty is present throughout the book, and it’s necessary. She’s comic relief, because what’s actually happening in the plot is heavy. It’s probably a requirement to read the previous book first, to be able to follow what’s going on, as it starts off pretty in the middle of things.
It’s dark and sad, and happy and silly. It’s an excellent read. Check it out.2


  1. Happy follow-up, though: I believe he’s since got the rights sorted out enough that he can resume his plans to write more in this world. 
  2. And join me in reading Roberts’ new book, in a totally different setting. I had the chance to read an early-release version of the first couple chapters a while back, and I’ve been looking forward to the full novel ever since. Hopefully I don’t take quite as long to get around to reading it as I did this one. 
Categories
Review

“Red, White, and Royal Blue,” or, “I was wrong about which genre this book was”

Casey McQuiston
I put off reading this one for a while, because it seemed like it was going to be dumb and fluffy, the sort of thing I like to save for when I’m stressed and need something easy and happy. And I’m quite happy to have been wrong about it, in part: while it’s certainly fluffy, it’s less dumb than I was expecting. Sure, the protagonist spends a bit too long not quite grasping what’s going on, but that actually gets turned around pretty well later on. And it’s a surprisingly good political novel, too — the backdrop of “being the son of the President” isn’t left as window-dressing, instead becoming a significant driver of the plot.
The cast is delightful — there’s a good deal of family drama going on, and it feels real, and rough at times.
All in all, I loved this book — stayed up too late reading it, laughed the way through, and would happily read it again. I can heartily recommend it.

Categories
Review

“The Plutonium Files,” or, “‘it’s a good thing we’re the good guys and the laws don’t apply to us,’ they said”

Eileen Welsome
I’m not sure what it says about me that all of my nonfiction reading is about the Cold War, but here we are again.
The funny thing about this book — and there isn’t much of that, because it’s a detailed account of some truly horrible things — is what did and didn’t stick in my mind. A lot of the book was about trying to humanize the victims of the experiments, and that aspect didn’t really land for me. The actual experiments, what was done, did stick, to a degree; having just finished my read, the ones I most remember are the prison experiments in Oregon and Washington, the radioactive iron supplements at Vanderbilt, a bit about the total-body irradiation experiments, and, of course, the titular plutonium trials. Some of the accidents also stood out to me — there’s a discussion of a man who took a plutonium criticality to the face, and the summary of how thoroughly screwed you are by that is that, when he threw up on the floor of the hospital an hour or two later, after they’d cleaned the floor, they had to get out a geiger counter to check if it was safe for anyone to walk there. (He didn’t survive; to add insult to horrible injury, his body was then parceled out to labs around the country, without the permission or knowledge of his next of kin.)
There were also a couple figures, dropped in as part of an anecdote in the portion of the book about the pilots who flew planes through mushroom clouds to measure their effects, that lodged in my head pretty effectively.
The first set of tests after WWII ended were called Operation Crossroads. The second of these was an underwater detonation; I’ve heard the story before that, during the explosion, a Japanese battleship was thrown — 30,000 tons of metal, launched out of the water. (I’ve been trying to confirm this story in writing this, but haven’t found any clear evidence either way, so I’m going to call it apocryphal and move on.)
This story, though, was from the Castle series, Castle Bravo, the first thermonuclear weapon test. 15 megatons of TNT; while it wasn’t a useable weapon — the device was the size of a small building, and had to be constructed in-place on the ‘target’ island — it was mind-boggling in scale. Because, 15 megatons of TNT, that’s… a number. But what the book described was a 20-mile-wide column of water and mud, 45,000 feet tall. Again, mind-boggling in scale, but slightly easier to conceptualize; just imagine a mountain, and then… make it taller.
The figure that truly got to me, though, was the statement that it took hours for the water and mud to finish falling back into the ocean. Hours.
These nuclear tests were also so bright that test animals, 350 miles away, got retinal burns from looking directly at it.
It’s a scale of destruction that I can’t fit in my mind. Humans aren’t equipped to think about this sort of thing.
And it’s not the scariest part, is the thing. Sure, you can erase a city in the blink of an eye.
This is where the book shines: it’s about the radiation, and just how scary and insidious it is. I’ve mentioned before that people aren’t afraid enough of nuclear war; at risk of sounding like a broken record, I’ll say it again. Write your Congresspeople, and advocate for disarmament, everyone.

Categories
Review

“The One Device,” or, “I’m amazed this man didn’t get arrested”

Brian Merchant
It’s rather fitting that I’m writing this review on my iPhone. Parts of the book were written on an iPhone, I suspect, and the author mentioned that a good deal of the interview recordings and photos were made on his iPhone.
Structurally, the book is interesting — there are two through lines, and they’ve got the same writing style but different feels. The more story-like one is the historical aspect, going from the beginning of the project through to the keynote where Steve Jobs introduced the world to the iPhone. And it’s a story, for sure: there’s a narrative to it, characters being introduced, politics and inventions, failures and triumphs. It’s the best telling of the story I’ve read so far, though admittedly I don’t think I’ve actually sat down to read the full story before.1
The other part is more of the ‘now’ aspect, which explores the impact of the iPhone as a product, focusing on the manufacturing process. The author tells how he… made his way into the Foxconn plant where iPhones are assembled; predictably gets hacked immediately after arriving at a hacker convention; goes on a claustrophobic tour of a tin mine; under-details an agoraphobic tour of the salt flats that produce most of the lithium used in the iPhone’s battery; and a few other stops along the way.
All told, it’s an interesting read. Some of the historical context was new to me—the history of ARM was inspiring, for example—and while I already knew a lot of things—photos of those lithium flats are pretty striking—I’m glad I took the time to read it. If you’re at all interested in the history, I can recommend the book.


  1. Creative Selection is on my list to read, so I’ll get there eventually. 
Categories
Technology

State of the Apps 2019

Inspired by CGP Grey’s post that started a Cortex tradition, here’s the current state of my phone:

This is… a work in progress. I got this phone in September, and while it’s been on my mind to do a full reorganization, I haven’t had time to do a full “tear it all down and start from scratch” process. The top two rows, especially, are very temporary — for the first time since iOS 7 came out, I’ve disabled Reduce Motion, and the parallax makes the fake invisible icons trick look terrible.
So rather than go through things in top-to-bottom, right-to-left order, I’m just going to talk about them in whatever order strikes my fancy.

  • Things remains my task management app of choice. I love it across all platforms, and happily recommend it to anyone who’s looking for something more robust than Reminders or a list in Notes. For me, it strikes the right balance of features without getting too heavy, and while I’ve got one or two things I’d like to see added, I have no great complaints.1
  • FoodNoms has been a very nice addition – it replaced Calory, which had replaced MyFitnessPal, which had replaced Lose It!. I’ve got a long history of tracking food, and while I quite liked Calory, FoodNoms is the first time I’ve gone “ah, never mind, don’t need this” and tossed out my notes on how I would build a food-tracking app. I haven’t yet gone for the subscription, because it just doesn’t have any features that interest me, but based on the rate of development, I’m expecting to make that change within the next few months.’
  • Timery is another stellar addition. It’s in that same category as FoodNoms — I had some sketches started of how I’d make an app in this category, and Timery made them completely irrelevant. The last two updates have added some truly excellent Shortcuts integrations — the last one added conversational shortcuts, so I can now just say “Hey Siri, Toggl” and talk through starting a timer with a specific project and description, or kick off a few frequently-used ones with a short phrase. The newest updated added some more programmatic stuff, and I’m planning to take some time over Christmas weekend to rebuild my old Toggl shortcuts, based on Federico Viticci’s examples, with Timery instead of custom web API calls.
  • Toolbox Pro – speaking of Shortcuts, Toolbox Pro is a neat little collection of Shortcuts actions. I’m most excited about the Variables feature, which I’m hoping I can use to improve some of my daily automation stuff.
  • Mail has replaced Airmail. I’d been vaguely looking for a replacement for Airmail, because it had a nasty habit of crashing all the time, and then they did a terrible job of switching to a new business model, and I threw my hands up in the air and decided to try the system default. It’s been working perfectly on iOS; on macOS, I’ve got a cobbled-together system using BetterTouchTool that sorta gives it real keyboard shortcuts,2 and a launchd script that relaunches it when it crashes.3
  • Day One remains my stalwart for journaling, but I’ve been slowly increasing the things I use it for. It’s my archive of Instagram, where I store my sketches, and the app I used to record some interviews I did for class.4
  • Ulysses is where I’m writing this article! It’s still my go-to for any long-form writing, and I love it. I haven’t yet made much use of their recent ability to store Ulysses files in Dropbox (or other arbitrary locations on disk), but I do have a collection of plain-old-markdown files that I edit in Ulysses on my Mac and Sublime Text on Windows.5
  • Reeder is a continuation and an addition all at once — I’ve been using it on my Mac for a while, but didn’t have it on iOS. I hit the maximum number of feeds on the free level of Feedly, and was extremely unimpressed with their paid offerings; I considered making a second account to keep syncing, but decided that was sorta rude to them, and instead opted to not have sync at all. That worked for a while, and then I got a Synology, and after setting it up as a Plex server, spent some time looking into RSS server options. At the moment, I’m using TT-RSS with a plugin for Fever support, but if anyone knows of something that’s easy to set up and has Google Reader API support, I’d appreciate it.6
  • Dark Sky’s recent redesign has me pretty happy. If they let me reorder the types of information, I’d be happier, but the clarity of the “when is it going to rain” charts is still excellent.
  • Overcast remains my podcast app of choice. Podcasts have been a great way to help me establish a gym habit — I established a podcast habit, and then decided that podcasts are things I can only listen to while driving, cleaning, or working out. (If you want podcast recommendations: Cortex, Do By Friday, ATP, 99PI, and MBMBAM are my mainstays.)
  • Strong, speaking of a gym habit, is the driving force of my time at the gym. A couple of my friends have been helping me out with designing actual workout programs to do, but Strong is where I put those in. It’s easy to use, remembers all the numbers so I don’t have to, and has instructions, often accompanied by images or GIFs, on a lot of exercises.
  • Streaks is where I track all my habits, from “did you remember to take your meds” to “do some writing for your blog” to “have you gone to the gym enough times this week?” It’s very good at what it does, and I’m still a fan.
  • Fluidics is a bit self-serving to include here, but I use it all the time. I’m planning to update it eventually — I’d like proper Dark Mode support, at the very least — but it’s hard to find the time.
  • Wallet has gotten more and more important over time, though not as fast as I’d like it to. Let me put my driver’s license in there, already. Apple Card is slowly taking over as my main credit card, Apple Cash is even more handy with the cash back in there, and it’s not too hard to make your own pass of your gym membership.
  • Sleep Cycle is possibly on it’s way out; I’m strongly considering getting a beddit, although I need to do more research — does it have the ‘smart alarm’ feature? How accurate is it? Is Apple going to kill the app soon? Lots of questions.
  • Dark Noise is a new addition in the past few days; I’ve been switching from a ‘sleep’ playlist to white noise in an effort to get Apple Music’s recommendations to not be entirely useless.7 I tried to use Sleep Cycle’s white noise feature for a while, but it assumes that I want the white noise to stop after a while, which is absolutely not the case. Dark Noise’s actual noise is a bit less interesting overall, which is possibly the point, and the app itself is delightfully well-made.

  1. I was, admittedly, tempted by OmniFocus, because OmniFocus for Web means I could have a single unified system across my Mac, iOS devices, and work PC, but it’s still just too much for my needs. And expensive. 
  2. Listen, Apple: you can either comp me the cost of getting a new keyboard that’s got the Inverted T arrangement for the arrow keys, or you can let me go from message to message using j/k. (And even if they did give me a free keyboard, I’d still complain; I’ve been using j/k to get around for two decades now, and it’s just easier.) 
  3. And on Windows, both Outlook and Windows Mail crash frequently, too; apparently IMAP, despite being 30-something-years-old, is still an unsolved problem? 
  4. In typing this, I’ve just realized that I think I’m using Day One the way Evernote wants to be used. Huh. 
  5. All synced by Git, because… why not? 
  6. The Fever API neglected any form of subscription management, and needing to pull up the TT-RSS frontend in a web browser whenever I want to add or remove a subscription just feels silly. 
  7. Fun fact: the “use listening history” setting that all Apple Music clients have? Doesn’t appear to do anything. Neither does “stop recommending music like this.” 
Categories
Programming

SwiftUI’s Picker

I’m very excited about SwiftUI, and have been using what little free time I have to do some tinkering with it. I started during the beta period, which was fun in between being very frustrating; a lovely side effect was that some of the knowledge I picked up is… entirely wrong. One that caught me was the implementation details for the Picker type.
Based on the rather rough state of the SwiftUI documentation for Picker and ForEach,1 I’d assumed that combining the right binding with a .tag(_:) on the items would work:

Form {
    Picker(selection: $selectedItemID, label: Text("Choose Something") {
        ForEach(items){
            Text($0.label).tag($0.value)
        }
    }
    Text("You've selected item \(selectedItemID)!")
}

For reference, the models I’m referring to throughout are pretty simple:

struct CustomModel {
    let value: Int
    let label: String
}

Now this looks like it’s working in simple cases. However, I was trying to interact with a web API, so that items array looked something like this:

var items: CustomModel[] = [
    CustomModel(value: 7, label: "First"),
    CustomModel(value: 3, label: "Second"),
    CustomModel(value: 1, label: "Third")
]

If you tapped “Second” in the picker that SwiftUI generated, however, the text wouldn’t read “You’ve selected item 3!” like it should; it would be “You’ve selected item 1!”
A bit more tinkering revealed that, instead of pulling the value from the .tag(_:) on there, it was just using… the index in the ForEach.2
After some frustrated Googling, utterly despairing of Apple’s documentation, and a lot of StackOverflow searches, I finally figured out the solution:

Form {
    Picker(selection: $selectedItemID, label: Text("Choose Something") {
        ForEach(items, id: \.value){
            Text($0.label).tag($0.value)
        }
    }
    Text("You've selected item \(selectedItemID)!")
}

Quite frankly, I don’t have a good explanation of what’s going on here; last time I was tinkering with Pickers, the .tag(_:) provided SwiftUI with the information it needed to do the binding. (When I’ve got more time, I’d like to do another test — now that I’ve got the id keypath, do I even need the tag?)
I’d love a good explanation of what all the id keypath gets used for, and where else it might be necessary, but alas:


  1. It’s a bit unfair for me to link to No Overview Available when referring to SwiftUI; the coverage is low, but the problem isn’t so much that as the fact that ‘documentation coverage’ just doesn’t work as a metric for something like SwiftUI. The tutorials are a start, and a good sign that Apple was at least trying to rethink their approach to documentation, but they’re not nearly complete enough. 
  2. Zero-based index, of course, which seemed obvious to me, but got me a “???” response when I was complaining about this issue to a non-programmer friend. 
Categories
Programming Technology Tools

Automated Playlist Backup With Swift

I mentioned in my post about scripting with Swift that I’d been working on something that inspired this. Well, here’s what it was: a rewrite of my automated playlist backup AppleScript in Swift. That version ran every hour… ish. Partly that scheduling issue is because launchd doesn’t actually guarantee scheduling, just ‘roughly every n seconds’, and partly it’s because the AppleScript was slow.1
Then I found the iTunesLibrary API docs, such as it is, and thought “well, that’d be a much nicer way to do it.”
And then I remembered that Swift can be used as a scripting language, cracked my knuckles, and got to work. (I also had some lovely reference: I wrote up my very basic intro post, but this post goes further in depth on some of the concepts I touched on.)

https://gist.github.com/grey280/0126ac93df1d52d91e78f52d97805246

Not the best API I’ve ever written, but not bad for something I threw together in a few hours. And I had fun doing it, more so than I did with the AppleScript one.
Oh, and it’s much faster than the AppleScript equivalent: this runs through my ~100 playlists in under a minute. So now I have it run every 15 minutes.2
(The configuration for launchd is about the same, you just replace the /usr/bin/osascript with the path to the Swift file, and make the second argument the full path to the directory where you want your backups going. See the original post for the details.)
I’m a bit tempted to turn this into a macOS app, just so I can play around with SwiftUI on macOS, and make it a bit easier to use. Of course, by ‘a bit tempted’ I mean ‘I already started tinkering,’ but I doubt I’ll have anything to show for a while — near as I can tell, SwiftUI has no equivalent to NSOutlineView as of yet, which makes properly showing the list a challenge. Still, it’s been fun to play with.


  1. I was going to cite this lovely resource, but since that website was built by someone who doesn’t understand the concept of a URL, I can’t link to the relevant section. Click ‘Configuration,’ then the ‘Content’ thing that’s inexplicably sideways on the left side of the screen, and ‘StartInterval’ under ‘When to Start’. 
  2. I’m also looking at the FSEvents API to see how hard it would be to set it up to run whenever Music (née iTunes) updates a playlist, but that… probably won’t happen anytime soon. 
Categories
Programming Technology

Swift Scripting

I’m a bit of a fan of Swift, though I don’t get to tinker with it nearly as much as I’d like. Recently, though, I did some tinkering with Swift as a scripting language, and thought it was pretty fun! (I’m planning another blog post about what, exactly, I was trying to do later, but for now just take it as a given.)
The most important step is to have Swift installed on your machine. As a Mac user, the easiest way is probably just to install Xcode, but if you’re looking for a lighter-weight solution, you can install just the Swift toolchain. Swift is also available for Ubuntu, which, again, takes some doing. If you want Swift on Windows… well, it’s an ongoing project. Personally, I’d say you’ll probably have better luck running it in Ubuntu on the WSL.
Alright, got your Swift installation working? Let’s go.
Step 1: Make your Swift file. We’ll call it main.swift, and in true Tech Tutorial fashion, we’ll keep it simple:

print("Hello world!")

Step 2: Insert a Magic Comment in the first line:

#!/usr/env/swift
print("Hello world!")

Step 3: In your shell of choice, make it executable:

$ chmod +x ./main.swift

Step 4: Run!

$ ./main.swift
> Hello world!

No, really, it’s that simple. The magic comment there tells your interpreter ‘run this using Swift’, and then Swift just… executes your code from top to bottom. And it doesn’t have to be just function calls — you can define classes, structs, enums, whatever. Which is the real benefit to using Swift instead of just writing your script in Bash; object-oriented programming and type safety are lovely, lovely things.

My next post is going to go into some of the more interesting stuff you can do, with a lovely worked example, but for now I’ll add a couple other things:

  • By default, execution ends when it gets to the end of the file; at that point, it will exit with code 0, so Bash (or whatever) will assume it worked correctly. If you want to exit earlier, call exit(_:) with the code you want. exit(0) means “done successfully,” while any other integer in there will be treated as an error.1
  • print(_:) outputs to stdout, which can be piped using |. If you want to output an error (to be piped with 2>, or similar) you need to import Foundation, and then call FileHandle.standardError.write(_:).2
  • To explicitly write to stdout, it’s FileHandle.standardOutput.write(_:).

  1. Which is useful if your script is going to be called programmatically. ./main.swift && echo "It worked!" will print “Hello world” and then “It worked!” with exit(0), but just “Hello world” if you add exit(1) to the end of the file. 
  2. And note the types here – this expects Data, not String, so to write a string, you need to convert it by adding .data(using: .utf8)!