Export Safari Reading List Items

This is something I should have done a while ago, but recently I started using my reading list for managing more items than in the past. After finally searching I found they’re stored within Safari’s bookmarks data (~/Library/Safari/Bookmarks.plist).

Using the plist library the reading list item urls can be extracted using python.

#!/usr/bin/env python
import os
import plistlib

# load bookmarks plist into dict
relpath = 'Library/Safari/Bookmarks.plist'
fullpath = os.path.join(os.environ['HOME'], relpath)
plist = plistlib.readPlist(fullpath)

# get the reading list node
for child in plist['Children']:
  if child.get('Title', None) == 'com.apple.ReadingList':
    bookmarks = child['Children']

# extract urls from each
urls = (bookmark['URLString'] for bookmark in bookmarks)

Then the urls can, for example, be opened in a different browser.

open /Applications/Google\ Chrome.app $(~/bin/readinglist-urls.py)

Why bother, use Pocket or Instapaper?

It’s a more universal “save url for later” because often the iPhone will open a share sheet with only a few options that includes saving to the reading list.

Pocket for me is for longer posts or articles that I save for times where I can lounge in a comfy chair or when travelling. My workflow with Safari’s reading list is odd, but its a temporary bookmark list that I can save links from any webview in any app I use on my iPhone and then I can take action when I’m back on my MacBook.

Resize Window Using GLFW3

When porting our game from mobile to desktop we wanted to add a few desktop specific interface enhancements. Things like using the keyboard, mouse, or managing the Window. By default games are setup to run full screen instead of within a window on desktop platforms, but since our game is pixel art full screen is a bit large on modern 24″+ monitors. So we’re sticking with running inside a window for now.

Ideally we’d allow players to resize the window. In order to support resizing a running scene we would need support to dynamically update every single UI element. Each scene or menu does size, scale, and position UI widgets on the current device (or now window) size, so we will allow changing resolution from a menu and then we will just reload that menu with replaceScene() after the changing the window frame size. We could build in support for this and attempt to unify the changes into a base class or small set of resize methods, but it would be better done at the first design and creation phase of a game’s development.

/// glview - the cocos2d-x platform OpenGL view reference 
/// frameSize - the desired window size
void OptionsResolutionMenu::static_changeResolution(GLViewImpl* glview, Size frameSize)
    auto glfwindow = glview->getWindow();
    auto fsize = glview->getFrameSize();
    auto screenSize = glview->getMonitorSize();
    int sw = screenSize.width > 0 ? (int)screenSize.width : 800;
    int sh = screenSize.height > 0 ? (int)screenSize.height : 480;
    // win position
    int winx = 0, winy = 0;
    glfwGetWindowPos(glfwindow, &winx, &winy);

    Rect viewport = glview->getViewPortRect();
    Vec2 viewcenter = Vec2(viewport.getMidX(), viewport.getMidY());

    // update the cocos2d view frame
    glview->setFrameSize(frameSize.width, frameSize.height);

    int x = int(sw - frameSize.width)/2;
    int y = int(sh - frameSize.height)/2;
    glfwSetWindowPos(glfwindow, x, y);

// call method with desired size (we get this from user options menu)
float resWidth = 800;
float resHeight = 600; 
OptionsResolutionMenu::static_changeResolution(glviewImpl, Size(resWidth, resHeight));
GameManager::getInstance()->runSceneWithID(kSceneOptionsResolution, 0);

Adding OS X Menu Bar with cocos2d-x 3.3

Update 2015-01-17: I’ve posted up an example project using cocos2d-x 3.3

I’ll post discussion topics here discussing adding or changing the Menu, but I found out adding MainMenu.xib didn’t work correctly as I have thought during the discussions over on the forum.

Looking into where the menu is created I found out that GLFW3 actually creates its own default menu with only two Menus services(App menu) and Window. The code where it sets this menu up is found in cocoa_window.m over on github.

Once I figured this out I had to investigate how to edit the app or window menu. Looking over the window code, and searching through the various header files from within XCode I was able to add an item to the Window menu.

void STDeviceMac::addMainMenu(GLViewImpl* glview)
    NSWindow * appWindow = (NSWindow *)glfwGetCocoaWindow(glview->getWindow());
        // make your obj-c calls here
        NSMenu* menu = [NSApp windowsMenu];
            NSMenuItem* menuItem = [[NSMenuItem alloc] initWithTitle:@"Check for Updates"
            [menuItem setTarget:[SUUpdater sharedUpdater]];
            [menu addItem:menuItem];
            NSMenuItem* menuItem = [[NSMenuItem alloc] initWithTitle:@"Steve's Test"
            [menuItem setTarget:_deviceImpl];
            [menu addItem:menuItem];

Update Your .App With Sparkle

Sparkle is a framework many OSX apps use in order to allow easy updating, automatically if desired. By default it effectively downloads the latest version of the .app package, checks authenticity with certificates, and finally replaces the previous .app with the newly downloaded package.

You can check out the project and download the lastest version from the projects website.

Then you’ll find the documentation to get the basic setup instructions over on github.

It does take a little more work to integrate than some other frameworks, but then this one is doing quite a bit more than just adding a library and some header files. It involves copying the framework into the app, adding a copy build phase, modifying the main window .xib, configuring the appcast (which is an RSS feed), and finally testing everything out. The documentation is good, but the lack of screenshots sort of fits. I’m sure I’ll run into issues so I’ll post them here as they occur.

Cocos2d-x uses GLFW3 for all of it’s platform window creation needs and by default creates its own menu so I had to add an extra menu item by calling into an Objective-C++ platform specific implementation.

Alfred is a better Calculator


Alfred is a tool that allows easily and quickly launching of applications typing only the first letter or two as well as quick access functionality like a calculator, search files, or reveal a folder in the finder. Yosemite was released with similar functionality in its improved Spotlight UI. I tried to use Spotlight for a week (my standard testing duration) and found that there were small aspects that didn’t fit into my workflow and I wasn’t willing to see if there were any workarounds or hacks.

Quick calculation is something I use surprisingly often whether for programming, game development, or figuring out how much I’ll pay in a year for Netflix. I used to open a new tab (a browser is open 99% of the time) and type in the math to use Google’s search calc, but it’s one less step with Alfred.

⌘+SPACE type in “=sqrt(33+44)” and hit [ENTER] and “5” is copied into the clipboard ready to paste wherever I please, even back into Alfred.

Spotlight has improved a lot with the latest upgrade, but Alfred makes many actions I want to make with less hassle, even if just slightly. It thinks more like I do and that’s why I continue to install and use it. I’ve recently bought the power pack and am looking into further expanding the level of automation by combining both the new capabilities it offers along with integrating it with scripts I have written.

There are other similar utilities, and they may be more powerful, but for the main essential functions Alfred is my launcher de jour.

Alternatives I’ve used