Mac OS X and Firefox – opening a new tab

There is a bug in Firefox on Mac OS X that opening a new tab from the command line (using the -new-tab option) doesn’t work – it tries to open a new copy of Firefox and fails:

Skjermbilde 2016-07-24 kl. 13.42.22

This seems to be a known issue that won’t be fixed (Bug 393645) – apparently something to do with the way that Mac applications communicate.

The workaround for this is an Applescript. The script below checks if Firefox is running. If it isn’t, it launches with the requested URL. Otherwise it activates Firefox, and fires the keystrokes to do the job.

on firefoxRunning()
tell application “System Events” to (name of processes) contains “Firefox”
end firefoxRunning

on run argv

if (firefoxRunning() = false) then
do shell script “open -a Firefox ” & (item 1 of argv)
else
tell application “Firefox” to activate

tell application “System Events”
keystroke “t” using {command down}
keystroke item 1 of argv & return
end tell
end if
end run

To run the script, enter the following on the command line:

osascript ffnewtab.scpt <url>

July 24, 2016   Tags: apps, macosx  No Comments

Running R scripts from Sublime Text

Here’s a quickie for running your R scripts directly from within Sublime Text by using the Build System functions.

Go to Tools -> Build System -> New Build System… and enter the following in the opened editor window:

{
    “shell_cmd”: “R –no-save –slave < $file"
}

Save it as something like “Run-R”, and it will appear in your Build System menu. Select it, and then you can run your script simply by pressing F7.

Note: I’ve only tested this on Linux so far. It’ll probably work OK on Mac OS X; Windows will probably need some adjustments to feed the script file into R. Let me know in the comments!

March 29, 2016   Tags: r, sublime  No Comments

Feedly, Pocket and IFTTT – with added videos

Feedly is my favourite RSS feed aggregator. The feature I use most is Save For Later, which does pretty much what you’d expect. This is great for storing up articles for when I have more time, but it’s a bit clunky for individual pages I come across – copy the URL, go to Feedly, paste it in.

For a while I was using Pocket for these ‘single page’ finds, because it has a nice Firefox extension to add pages in a single click:

pocket

This works really nicely, except now I have things stored in two different places. Not ideal. At this point, IFTTT comes to the rescue. I can create a recipe that takes anything I save in Pocket, and copy it straight into my Saved For Later list in Feedly. Genius.

pocket_feedly

A natural extension to this idea is to save videos for later watching. YouTube both has a Watch Later feature, and IFTTT can watch for these, so it’s trivial to create a recipe that adds Watch Later videos to Feedly’s Save For Later. Unfortunately, Feedly doesn’t seem to be able to extract the video titles from these videos, so your list of items gets a bit vague:

bad_title

It turns out that Pocket is able to get the titles successfully, so the solution is simple. Create recipes that submit Watch Later videos to Pocket, and then the Pocket to Feedly recipe will transfer them – with the video titles intact.

good_title

Sadly the site name is still broken, but I can live with that. More sadly, this trick doesn’t work with Vimeo videos. I may have to prod Feedly and/or Vimeo to see if they can work out how to rectify it. But still, it’s an improvement for YouTube, and sometimes we just have to take what we can get.

March 13, 2016   Tags: feedly, ifttt, pocket, vimeo, youtube  No Comments

Changing the default browser in Thunderbird

I have spent a very long time trying to work out how to change the default browser in Thunderbird on Linux. All the tutorials I’ve found tell you to edit settings through the Advanced preferences menu, or by editing prefs.js. Neither of these worked for me.

After a lot of exploration, I’ve discovered that there’s a special file that controls Thunderbird’s choice of browser:

~/.local/share/applications/mimeapps.list

On my machine, this contained the following:

[Default Applications]
text/html=chromium-browser.desktop
x-scheme-handler/http=chromium-browser.desktop
x-scheme-handler/https=chromium-browser.desktop
x-scheme-handler/about=chromium-browser.desktop
x-scheme-handler/unknown=chromium-browser.desktop
x-scheme-handler/mailto=thunderbird.desktop
message/rfc822=thunderbird.desktop
application/x-extension-eml=thunderbird.desktop

[Added Associations]
message/rfc822=thunderbird.desktop;
application/x-extension-eml=thunderbird.desktop;

You’ll see that everything is pointing to the chromium-browser.desktop application definition file – not what I wanted. So I simply shut down Thunderbird, replaced everything to firefox.desktop, and restarted. (The file should now look like this:

[Default Applications]
text/html=firefox.desktop
x-scheme-handler/http=firefox.desktop
x-scheme-handler/https=firefox.desktop
x-scheme-handler/about=firefox.desktop
x-scheme-handler/unknown=firefox.desktop
x-scheme-handler/mailto=thunderbird.desktop
message/rfc822=thunderbird.desktop
application/x-extension-eml=thunderbird.desktop

[Added Associations]
message/rfc822=thunderbird.desktop;
application/x-extension-eml=thunderbird.desktop;

Everything is lovely again. The slight caveat is that links are always opened in a new window. It would be a trivial matter to create your own version of the firefox.desktop file which includes the command line parameters for opening the link in a new tab instead, but I’ll leave that as an exercise for you.

January 27, 2015   Tags: apps, linux/ubuntu  No Comments

AnimatedPNG Update

It’s been six years since I last touched AnimatedPNG, yet it still gets downloaded around once per day on average. For such a simple little library it’s clearly useful to a reasonable number of people, which is very gratifying.

I once had grand plans to add loads of new features to the library, but to be honest I really don’t think it needs them – in fact, I think the simplicity is probably its greatest feature.

Having said that, I was asked for a simple way to clear out the custom frame delays (that allow you to have variable animation rates), rather than having to reset each frame by hand. So I did it, as it doesn’t add any complexity to its use. Details are on the AnimatedPNG pages.

November 13, 2014   Tags: animatedpng  No Comments