Showing posts with label OS X. Show all posts
Showing posts with label OS X. Show all posts

Thursday, 12 March 2020

Catalina Jekyll bad interpreter error

Problem:

When trying to run jekyll in Terminal, I get the following error:

zsh: /usr/local/bin/jekyll: bad interpreter: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: no such file or directory

I recently upgraded MacOS.

Before you start:

This how-to assumes you already have knowledge of Terminal and the 'sudo' command, given that you've already installed Jekyll in the past. If not, please proceed at your discretion as 'sudo' command can be harmful if used incorrectly.

Solution:

In Terminal, reinstall jekyll via homebrew:


sudo gem install jekyll

Why this works:

The upgrade to Catalina changed key dependencies of Jekyll. While it is possible to manually link them or add them to your PATH, reinstalling Jekyll should provide an easier and more robust solution. You'll likely also need to reinstall any other gems you need.

Disclaimer:

This solution was verified to work in MacOS 10.15.3 with Jekyll 4.0.0. Your mileage may vary with other versions.

References:

Tuesday, 30 January 2018

Cannot type into Spotlight in macOS

Problem:

I suddenly cannot type anything into Spotlight.

It opens and closes, and even does so with the Command-Space shortcut. I just can't type in it when it's open.

Workaround:

  • Open Terminal
  • Use the following command:
    killall Spotlight
  • If all goes well, the magnifying glass for Spotlight will disappear and reappear, and you'll be able to type into Spotlight again

Notes:

This was tested to work in macOS 10.12.6.

Tuesday, 16 January 2018

XQuartz move offscreen windows back on-screen in macOS/OS X

Problem:

I have several XQuartz/X11 windows in macOS/OS X that are offscreen. I want to move them on-screen so I can save my work.

Example scenario:

You can create an example of off-screen X11 windows when using macOS/OS X with an external monitor and a screen geometry where one monitor is higher and further left to another (scroll down to see a screenshot example).

In the lower-right monitor, when opening certain windows in programs like Inkscape, those windows will be created at coordinate that you cannot access with your mouse cursor.

Workaround:

Pre:

  • If not already installed, then install xdotool (easiest way is to use Homebrew)

To find out window ids and geometry:

  • In Terminal, you can use:
    xwininfo -tree -root
  • If you want to filter by an application, you can pipe to grep, for example:
    xwininfo -tree -root | grep "inkscape"

To move a window to a visible coordinate:

  • If not already installed, then install xdotool (easiest way is to use Homebrew)
  • Make note of a valid coordinate. Use the output of xwininfo from the above step to find a visible top-left coordinate for your window (e.g. it can be an existing window that you can already see and use with your mouse. In the screenshot below, a visible coordinate is 1070 1102)
  • In Terminal, use the following command and replace [options] [window] [x] [y] with the appropriate values:
    xdotool windowmove [options] [window] [x] [y]

Example:

Consider the following window geometry:

Inkscape has spawned the "document properties" window to a coordinate that is out of desktop 1:

Use xwininfo to find out window IDs, geometry, as well as to to find a set of on-screen coordinates:

Use xdotool to move off-screen window to an on-screen coordinate on desktop 1:

If all goes well, the window should now be visible.

Now would be a good time to save your work.

Also note that there might be some unexpected behaviour for XQuartz windows moved this way (e.g. "show all windows" still shows incorrect placement, etc.)

Where to go from here?

Some ideas:

  • write a script to automatically collect all windows of a certain app into visible coordinates if they're not visible
  • if you're able to and have the time to volunteer, contribute to the XQuartz project a feature to collect or clamp all windows to a given desktop :) (thanks in advance!)

Notes:

This workaround was verified to work with macOS Sierra 10.12.6, XQuartz 2.7.11, xdotool 3.20160805.1. Other versions may have different results.

References:

Monday, 15 January 2018

Exit XQuartz Full Screen Mode macOS Sierra

Problem:

How do I exit XQuartz full-screen mode?

Solution:

When in XQuartz:

  • Press the keyboard shortcut Command-, (command + comma)
  • Uncheck full-screen mode in the preferences

References:

Friday, 12 January 2018

How to take Touch Bar screenshots on Mac

Problem:

How do I take a screenshot of the Touch Bar on a Mac?

Solution:

To take a Touch Bar screenshot and...

  • ...save as a file on the desktop: Shift-Command-6
  • ...copy to clipboard: Control-Shift-Command-6

Example Screenshot:

Notes:

The shortcuts in the solution above are defaults. They can be configured by going to "System Preferences" -> Keyboard -> Shortcuts -> "Screen Shots", and setting new shortcuts.

The how-to was verified to work in macOS 10.12.6 on a MacBook Pro with a Touch Bar. Your mileage may vary with other OS versions.

References:

Thursday, 11 January 2018

USB-to-Serial on OS X/macOS - an Example

Problem:

I have a USB-to-Serial adapter that I need to use on a Mac. How do I configure it, and how do I read/write to it?

I am already partially familiar with using serial ports on Linux and Windows.

Notes:

This post is written as a reminder and contains just enough information to reproduce these steps in the future. It is not thorough. A little Google may be required in order to clarify or expand on some points.

The following steps were verified to work with macOS 10.12.6, with a very specific USB-to-serial adaptor that happened to work fine with Apple's default drivers. Your mileage may vary with other configurations and devices.

Steps Overview:

  1. Before you start, if drivers do not already exist then install them.
  2. Plug USB-to-Serial adaptor into your Mac
  3. Find info in "About this Mac" - More below
  4. Setup null modem and speed using Network Preferences - More below
  5. Find the device's path to access the Linux/POSIX way - More below

Step: Find adapter info:

To find out some basic information about your USB-to-Serial adapter, use the following steps.

  1. Go to "About This Mac" and click "More Info..." or "System Report..." (depending on your OS version)
  2. Find your device in the system report under "USB", and make note of what is there. This will help you identify your device in other steps.

Step: Configure serial communication using Network Preferences

To configure your USB-to-Serial adapter speed, etc., for use with other apps on your Mac, use the following steps.

  1. Open "System Preferences" and open the "Network" preferences pane
  2. Select your USB-to-Serial adapter if it is in the list, or add it then select it
  3. Click "Advanced..."
  4. Configure as null modem with the desired baud rate. The example screenshot below shows the attached device configured to 9600 bps (as well as some other configuration)

Step: Access your usb-to-serial port the Linux/Posix way:

  • to find the path to your serial port, in Terminal type in the following command and find your device:
    ioreg -c IOSerialBSDClient | grep usb
  • in the example screenshot above, the serial port is "/dev/cu.usbserial-FTAN3DQ" and an example of its use in VirtualBox is shown in the screenshot below.
  • (optional) to test your serial port directly, you can use the "screen" command in Terminal. More on this command in Apple's screen man page

    References:

  • Thursday, 24 December 2015

    BlackBerry Link El Capitan USB connection unstable

    Problem:

    My BB10 BlackBerry device won't back up using BlackBerry Link in OS X El Capitan. The USB connection keeps dropping. USB is fine with all of my other devices.

    Solution:

    • Make sure BlackBerry Link is installed, and your Mac has been restarted
    • Make sure your BlackBerry is plugged into your Mac via USB
    • Navigate to Apple Logo (top right) -> System Preferences -> Network
    • At the bottom of the list on the left, click the plus button + (this will add a network interface)
    • In the "Interface" drop down, note any BlackBerry interfaces that haven't already been added to the list (in the case of this machine, it was "BlackBerry (en4)")
    • Add the BlackBerry interface, and then hit "Apply"
    • Open BlackBerry Link, it might ask for your device password and then connect properly
    • If successful, operations such as backup will now work without dropping

    Notes:

    This was verified to work using OS X 10.11.2 (El Capitan), a BlackBerry Passport, and BlackBerry Link 1.2.2 (build 32). Your results may vary.

    Some operations, such as syncing photos, might not work (i.e. iPhotos has now been replaced by Photos, and syncing photos requires iPhoto; other changes apply).

    Additionally, the above steps worked on a machine with a fresh install of BlackBerry Link, and without BlackBerry Blend installed. If the above steps work or do not work with both software installed, please follow the links in the references section for more information.

    References:

    Monday, 3 February 2014

    How to detect displays in OS X 10.9 Mavericks

    Problem:

    How do I detect displays in OS X Mavericks? The Systems Preferences option to detect displays seems to be missing.

    Solution:

    While in the "Displays" Systems Preferences panel, press the "option" key and the "Detect Displays" button will appear when using OS X Mavericks.

    Image below: OS X 10.9 Displays panel with the "Detect Display" button missing by default

    Image below: OS X 10.9 Displays panel after pressing the "Option" key

    Notes:

    This was tested to work in OS X 10.9 and 10.9.1. Your mileage may vary in other versions.

    References:

    Tuesday, 7 January 2014

    Disable Mac start-up chime in OS X 10.9 Mavericks ("Band-Aid" workaround only, for now)

    Problem:

    I would like to disable the start-up chime my OS X Mavericks-based Mac makes so that restarting the computer will not be so loud.

    Notes:

    • The solutions below were tested on OS X 10.9 Mavericks and may work on other versions, but there is no guarantee.
    • This how-to was written as a reminder for myself in case this needs to be replicated or undone later. It is not a full solution and still a bit advanced for the average OS X user to follow, which makes it unacceptable to post as a "solution" (in my opinion).
    • You're welcomed to follow the solutions below, but use the more permanent one at your own risk.

    Solution 1 (temporary):

    Turn the volume of your computer down before shutdown or restart. The start-up chime should match your system's volume.

    Note that muting seems to have mixed reported results in forums and other online posts, where some systems will chime at the same volume as the system volume, even when muted (resulting in lots of surprise chimes), yet others report that muting works.

    Solution 2 (advanced workaround, but a bit more permanent):

    This solution goes through the steps to write a script that turns the system volume to 0, and rigs it to run upon the user selecting to shutdown or restart the machine via the apple menu.

    Warnings:

    • Make sure you are comfortable with Terminal, shell scripts, file permissions, and reading manual pages (if you get stuck). If you are not comfortable using Terminal (or are prone to making typos), you should probably not try this. Attempt at your own risk.
    • Every time you start up OS X, the volume will be set to 0 (which may not be a bad thing if you're already trying to avoid surprises by turning the chime sound off to begin with)

    This is a modification of the solution found here, but modified in a way that should work on more OS X setups. The modified steps are posted below as a reminder in case the link ever goes down.

    Steps:

    1. Run the Terminal app with an administrator account
    2. Create a script for muting (replacing "/path/to/" with a valid path -- if you're not sure what this means, do not proceed with the rest of the steps)
      sudo nano /path/to/volume-off.sh
      
    3. Write the volume-off script (or copy and paste the following into it):
      #!/bin/bash
      
      osascript -e "set Volume 0"
      
    4. Make file executable with following command (replacing "/path/to/" with where the script is saved):
      sudo chmod u+x /path/to/volume-off.sh
      
    5. Check that we can hook this to the OS X logout (see if any hooks exist - only one or none can exist, not more). In Terminal, use the command:
      sudo defaults read com.apple.loginwindow LogoutHook
      

      You should end up with something similar to "The domain/default pair of (com.apple.loginwindow, LogoutHook) does not exist".

    6. Add hook to run script at logout, replacing "/path/to/" with where the script is saved:
      sudo defaults write com.apple.loginwindow LogoutHook /path/to/volume-off.sh
      

    To Undo Solution 2:

    1. Check that the logout hook exists in Terminal with the following command:
      sudo defaults read com.apple.loginwindow LogoutHook
      

      You should end up with something similar to "/path/to/volume-off.sh" with "/path/to/" being where your script is saved.

    2. Delete the logout hook in Terminal with the following command:
      sudo defaults delete com.apple.loginwindow LogoutHook
      

    Notes on solution 2:

    • Just like in the original solution, the volume-off.sh script is also saved in /Library/Scripts/
    • Make sure the permissions of the script is set so that only the owner can write to the file, since the script is run as sudo (and would be an obvious security risk if it can be re-written by just anyone).
    • The script must be owned by root.
    • Again, this will turn the volume to 0 upon logout rather than simply mute. This is because many people online seem to report mixed success with muting.
    • The commands for setting both a login and a logout hook, as well as removing them are as follows:
      • sudo defaults write com.apple.loginwindow LoginHook /path/to/your-login-script.sh
      • sudo defaults write com.apple.loginwindow LogoutHook /path/to/your-logout-script.sh
      • sudo defaults delete com.apple.loginwindow LoginHook
      • sudo defaults delete com.apple.loginwindow LogoutHook
    • The commands for checking if a hook exists for login or logout are as follows:
      • sudo defaults read com.apple.loginwindow LoginHook
      • sudo defaults read com.apple.loginwindow LogoutHook

    Very brief discussion on problems with other solutions found online:

    The following will only make sense to anyone who has Googled how to disable the start-up Mac chime and read through the various proposed solutions. It briefly outlines why these workarounds weren't posted here. You can skip this section if you'd like.

    nvram SystemAudioVolume method:

    1. too dangerous for most users (you can easily accidentally turn your computer into an expensive paperweight with the nvram command)
    2. many mixed results and uninformed posts online on why that solution used to work (read: everyone seems to be guessing. If you don't want to be one of those guessers, you can read up on nvram in the slightly out-of-date book "Mac OS X for Unix Geeks (Leopard)" in Google Books as that section appears to be viewable for free, at least as of January 2014)
    3. the solution doesn't work on all OS X and Mac combinations
    4. the solution does NOT work in Mavericks (tested) as the system will change the SystemAudioVolume value automatically

    rc startup/shutdown script method:

    1. does not work in Mavericks as start-up has been moved to launchd instead (see Apple developer documentation on Launch Daemons and Agents
    2. any daemon-supporting mechanism may change in future versions of OS X, making this solution possibly unreliable (and worse, it will leave potentially unwanted files dangling deep within the system)
    3. this solution is way too complicated to post for the average user

    existing software:

    1. many don't work on all versions of OS X (mixed results reported in forums, etc.)
    2. all software Googled do not describe exactly what system-wide changes are being made, making it hard to determine how permanent they are, as well as how well do they handle OS upgrades
    3. Mavericks seems to have broken a lot of the existing software, so it's hard to recommend a good one

    the solution 2 in this blog post:

    1. it's not possible to do if you are not the system administrator
    2. it's not possible to do if you or your system administrator has already hooked something to com.apple.loginwindow LogoutHook
    3. it's possible that it won't work if you shut down your computer using a different mechanism than the usual Apple UI ways
    4. it's still inaccessible to most users
    5. if permissions are not set correctly, you could potentially create a security hole

    an official Apple "turn off start-up sound" preferences item:

    1. does not exist/was eliminated
    2. if you're from Apple, perhaps you could help out with this? =)

    References:

    Friday, 6 December 2013

    Create an ISO disk image from a CD/DVD in OS X

    Problem:

    I would like to back up a disc to an ISO image using OS X. (This can be useful when backing up personal content such as photo albums, home movies, etc.)

    Solution:

    • Insert disc into disc drive
    • Open the "Disk Utility" application (Application -> Disk Utility)
    • Select your disc drive
    • Click on "New Image" (one of the buttons on the top of the window)
    • For "Image Format", select "DVD/CD master" (on the bottom)
    • Pick a filename and click "save". This should create a file with a .cdr extension
    • When the image is done being written to disk, rename the extension to .iso

    Troubleshooting:

    • If the original image does not have an extension .cdr, but instead has an extension .dmg, etc., "DVD/CD master" was not selected. Restart the process, but this time select "DVD/CD master" as the image format.

    Notes:

    This should work on most versions of OS X until 10.9, and possibly even beyond. This how-to was tested to work using OS X 10.7 through 10.9.

    References:

    This how-to was adapted and condensed from the link below. It was written as a reminder, in case the page below ever goes down.

    Thursday, 5 December 2013

    Workaround to place XQuartz/X11 apps on second monitor in OS X Mavericks (apps like Inkscape)

    Problem:

    I've upgraded to OS X Mavericks and I can't place apps such as Inkscape on my second monitor any longer. I don't want to turn off "Displays have separate Spaces."

    Before trying this workaround ...

    This workaround was written as a reminder for myself. Even if you get it to work, X11 programs will be riddled with bugs because of how Mavericks currently treats Spaces coordinates, gravity, etc., with XQuartz. Thus, I'd recommend not following it for the time being unless you're curious. A better workaround is to simply turn off "Displays have separate Spaces" in: System Preferences ... -> Mission Control

    This workaround only works under very specific conditions right now, and there is no guarantee that it will work under other conditions. The following are the conditions under which this workaround worked:

    • The OS X Team nor the XQuartz team have not addressed the issue yet (test this out to make sure that you're not using a workaround when things actually work)
    • OS X version is 10.9
    • XQuartz is installed and works
    • XQuartz version is XQuartz 2.7.4 (xorg-server 1.13.0) or under (haven't tested it with newer versions, and newer versions may fix this problem rendering this workaround pointless)
    • Inkscape and other X11 apps run
    • "Displays have separate Spaces" is checked under: System Preferences -> Mission Control
    • You haven't already dragged the application window out of bounds in one of your spaces (in which case you'll need to figure out how to reset its position first -- can't help there at the moment since each app handles its position in different ways. Advanced: Try resetting or reinstalling the X11 app, or editing its config file?)
    • You know what the following terms mean: "dock", "desktop", "mission control", "spaces", "X11", "XQuartz", "secondary click"

    If you're here to try to get Inkscape or other X11 apps to work in Mavericks in the first place, try this post first: http://grammarofdev.blogspot.ca/2013/10/how-to-run-inkscape-in-os-x-109.html

    Disclaimer:

    This is hardly a permanent solution, nor is it guaranteed to work under all versions of OS X, XQuartz, etc. This workaround is just posted here in case anyone else finds it useful to be able to use X11 apps on their second monitor once again after upgrading to Mavericks, and doesn't mind jumping through a few hoops. Hopefully by the time you read this, someone at Apple or XQuartz would have fixed this issue. (If you're one of said Apple or XQuartz people, please fix this =) lol.)

    Also note that because the bug seems to be related to coordinates, weird things can happen with this workaround, such as windows, child-windows, etc., opening out of bounds and therefore off-screen. Hopefully someone out there will be able to debug this problem as this workaround can't work around bugs like that.

    Workaround:

    • Launch the X11 app so that XQuartz and the app's icon show up in the OS X dock
    • In the dock, secondary click the XQuartz icon and select: Options -> Assign To: None
    • In the dock, secondary click the app icon and select: Options -> Assign To: None
    • Go to mission control (hit f3 on most Macs, or triple-swipe upwards if that gesture is enabled)
    • Do NOT attempt to drag the app to the space/desktop on the other monitor as you do with native apps, as all this will do is set the window out of bounds on the current space/desktop. (At least, as of XQuartz 2.7.4 (xorg-server 1.13.0) or earlier.)
    • Drag the X11 app window (such as Inkscape's window) to the desktop/space mini-window on top of the other monitor (the one on top with the labelled "Desktop __" with the desktop number in place of __ -- not to the big desktop area below)
    • If all worked out, the app should now actually display on your second monitor
    • (Optional step - if you work for Apple) Program a patch to allow drag-and-drop of X11 apps to spaces residing on second monitor
    • (Optional step - if you work on the XQuartz project) Detect bounds of monitors and imitate native drag-and-drop behaviour (I'd like to help out, but I'm not entirely sure how to right now =/)

    More:

    As this issue hasn't been solved yet as of the time this post was written, I've decided instead to link to the closest bug report that I could find: https://discussions.apple.com/message/23717540#23717540

    If you happen to have a better fix, please feel free to update us all in the comments below! =)

    Monday, 28 October 2013

    How to run Inkscape in OS X 10.9 Mavericks

    Problem:

    After upgrading to OS X 10.9, Inkscape, as well as other X11 apps do not seem to work any longer. How can I run Inkscape?

    Solution:

    • Install Inkscape (if haven't done so already) from http://inkscape.org/
    • Install XQuartz from http://xquartz.macosforge.org/landing/
    • Run Inkscape.app
    • When asked for "Where is X11?", click "browse ..." and select /Applications/Utilities/XQuartz.app (or just /Applications/Utilities/XQuartz)

    Explanation:

    As of OS X Mountain Lion, Apple no longer installs the X11.app by default, which was previously needed to run any X11 applications. XQuartz or another compatible X Server is now needed to run any X11 apps as a result. A full explanation can be found in the Apple knowledge base article here: http://support.apple.com/kb/HT5293

    Additional comments:

    This solution was tested to work with the default installation of OS X 10.9 and Inkscape 0.48.2.

    Note that if XQuartz starts up when launching Inkscape, but Inkscape doesn't launch the first time along with XQuartz, (or the Inkscape window doesn't show up), you can try to quit both Inkscape and XQuartz, then launch Inkscape once more (which should also launch XQuartz). This bug occurred on the system that the above fix was tested on, and the workaround seems to have worked. Your mileage might vary.

    Addendum:

    (Added in 2014)

    A useful post from commenter @Birtanish below seems to have helped a few people when the above instructions weren't sufficient, so it's reproduced below in case it helps. Best of luck!:

    "Hi! I tried the above solution which in the end did not work at all unfortunately. Another solution is to launch Inkscape from within XQuartz, this is done by opening a terminal and type: open /Applications/Inkscape.app Additionally it is possible to create a shortcut for this in the XQuartz menu, by clicking on Applications -> Customize and the above command as the command and set name to Inkscape for instance. This worked for me, hope it can help somebody else as well. Good luck."

    Saturday, 7 September 2013

    VirtualBox OS X Host Ubuntu Guest - USB device captured but not mounting/showing - One workaround

    Problem:

    I am using VirtualBox 4.2.x on OS X 10.7.x running an Ubuntu Guest. When I try to plug in a USB device, such as a USB drive, USB MIDI keyboard such as the Keystation 88-es, etc., VirtualBox shows the device as captured (with a checkmark in the USB devices list), yet Ubuntu can't find it. I've already tried things such as installing VirtualBox Guest Additions, setting proper user permissions, etc.

    One Workaround:

    If you've managed to mount and capture the USB device but it's still not showing, you've probably already made it past most How-To's Googling will offer. One bug fix that seems harder to come across is this: Set the number of virtual CPUs to 1.

    Apparently after VirtualBox version 3.2.0, a bug has caused USB devices to not show up in some Linux-based guests when the number of virtual CPUs is set to more than 1.

    If this obscure bug fix doesn't help, check out the references below to lots of other potential solutions to the USB-won't-mount problem.

    Good luck!

    Notes:

    I realize that this post isn't complete, however it was this one somewhat obscure bug that caused many hours of attempted debugging and Googling until it was found. So to save others the trouble of finding it buried in a page full of instructions and fixes, I opted to highlight only this one bug, and link to other pages full of good solutions.

    Hopefully by the time you've reached this blog page Oracle, VirtualBox, Apple, or some others have managed to fix the problem!

    This workaround is version specific so your mileage may vary depending on the version of OS X, VirtualBox, VirtualBox Guest Additions, Linux, etc., that you are running.

    References:

    Wednesday, 21 August 2013

    Inkscape 0.48.x OS X extensions problem workaround

    Problem:

    When using extensions with Inkscape 0.48.2 in OS X I get an error similar to: "the fantastic lxml wrapper for libxml2 is required ..." and extensions won't work.

    Prerequisites:

    This workaround worked on the system it was used on, however the solution is potentially version specific. The versions of stuff installed on this system were:

    • OS X 10.7.5 with the installation of Python that came with it
    • Python 2.7.5 (you can find your version in the terminal by typing "python --version")
    • Fresh install of Inkscape 0.48.2
    • XCode (required to compile the modules that we're going to install)

    Notes:

    The following steps are not necessarily a permanent fix for this problem, however they worked on the system that they was tested on. Your mileage may vary as the problem seems to be version-specific. Make sure you know what you're doing and follow the instructions at your own risk. If you're unsure, refer to the links in the references for a more complete explanation before starting. Good luck!

    Workaround:

    This problem is caused by the OS X version of Inkscape not being able to find the version-specific Python module for libxml2 that it was compiled/packaged to use. OS X comes with its own version of python which happens to be missing a few things usually installed in other operating systems. To install the required modules for Inkscape extensions to work, the following steps were taken (though not all may be required for this workaround to succeed.)

    This workaround is a combination of two solutions found on internet forums. One of them modifies Inkscape to use version 2.6 of python if it's on the system. (If it is, that modification can be done without installing the libxml modules). The other installs the libxml2 module Inkscape is looking for in version 2.7 of python.

    If you're not comfortable with using the terminal, there's an unofficial patch you can install instead of using the below workaround. It can be found at this forum thread: http://boardgamegeek.com/thread/769281/installing-on-osx-lion-the-fantastic-lxml-wrapper (just search for "EggBot2.2.2.r2.mpkg.zip")

    Caution: do not proceed if you are not comfortable with the Terminal, command line, or code editing

    • Make sure your install of Inkscape is a fresh, unmodified copy
    • Make sure your python 2 version is at least 2.7.5 (as this workaround was only tested with that version) If it's older, you can get 2.7.5 here: http://www.python.org/download/
    • Open Terminal
    • The following steps may produce errors. If they do, look at the errors and try to fix them to complete the steps before moving on! (The usual: Google if unsure, or do not proceed further)
    • Type the command "sudo easy_install pip" to install the python package manager pip
    • Type the command "sudo pip install virtualenv" (probably not required, but useful)
    • Type the command "sudo pip install lxml"
    • If there are no errors in the above few steps, you're good so far. If there are any errors, try to get the steps to complete without errors (the usual: look at the errors, Google a solution, etc.)
    • In a text editor, open the file "/Applications/Inkscape.app/Contents/Resources/bin/inkscape"
    • Above the line 32 (which reads: "export VERSIONER_PYTHON_PREFER_32_BIT=yes"), add the following line without quotes and save the modified file: "export VERSIONER_PYTHON_VERSION=2.6"
    • (Note that the python version 2.6 specification in the inkscape file may not do anything if version 2.6 isn't on the system, and inkscape may just default to the system's version of python. The above steps to install lxml should make libxml work on the current version of python nonetheless.)
    • Restart Inkscape. The extensions menu should work now.

    References:

    Friday, 15 March 2013

    Disable spelling autocorrect in Safari

    Problem:

    I'd like to disable spelling auto-correct in Safari!

    Solution:

    Using OS X 10.7 or higher, there are at least two ways to disable automatic spelling correction: globally, and on an individual app basis. Disabling autocorrect can be useful for those who often need to spell out things that would come up as incorrect in the dictionary, such as HTML CSS style editors who need to use "center" instead of the autocorrected "centre".

    To disable automatic spelling correction globally (at least across apps that use OS X's dictionary):

    • click on the apple icon on the top-left of the screen
    • click on System Preferences ...
    • click on Language & Text
    • click on the Text tab
    • uncheck Correct spelling automatically

    To disable automatic spelling correction in Safari:

    • first click on any text field where you can type (otherwise the relevant menu option will be greyed out)
    • in the menu on the top of the screen, click Edit -> Spelling and Grammar
    • if checked, uncheck Correct Spelling Automatically

    Notes:

    Both of these worked using Safari 6.0.2 under OS X 10.7 and 10.8. Your mileage may vary across other versions of OS X and Safari.

    Tuesday, 5 February 2013

    Selectively and recursively copy all files of a single file type in OS X and Linux

    Problem:

    In OS X or Linux, how do I selectively copy only one type of file to a folder? For instance, how can I recursively copy all .mp3 files from a folder with many sub-folders into a single folder?

    Solution:

    Note: this solution assumes you have basic knowledge of using the Terminal and know how to avoid destructive commands.

    To recursively check the paths of all files for instance all .mp3 in a folder and all its sub-folders, type the following into the Terminal (replacing the path and file extension to fit your need):

    find /path/to/files/to/search -iname '*.mp3'

    If everything looks alright, to copy the files use the following command (replacing the paths and the extension to fit your need - also note that this is a single line/command, but it's long so it may wrap to more than one line in your browser):

    find /path/to/files/to/search -iname '*.mp3' -exec cp {} /path/to/destination/ ./mp3 \;

    Important: make sure that the / is at the end of the destination path! (It will all be copied as a single file otherwise as it'll think that your destination is a file name and not a folder.)

    Saturday, 22 December 2012

    Install pattern files into GIMP 2.8 in OS X

    Problem:

    How do I install patterns into GIMP 2.8 in OS X?

    Solution:

    One way to do this is to copy the .pat files directly into the GIMP folder that contains all of the default GIMP pattern files. To find this folder, follow the steps below:

    • open your Applications folder
    • secondary-click GIMP, and select "Show Package Contents" from the context menu
    • navigate to: Contents/Resources/share/gimp/2.0/patterns

    Now that you've found the patterns folder, copy all the GIMP-compatible pattern files into this folder. Restart GIMP. You should now be able to see the new patterns in the patterns dialogue/selector of GIMP.

    Notes:

    Note that the above method will make the patterns you install available for every user of your system. There are other methods available which should only install it to your own user, but they may not be so straightforward for the typical user since they involve creating/opening hidden folders.

    If you'd like to find out the alternative locations where GIMP is looking for pattern files, just follow these instructions:

    In the main menu, click on (in OS X) GIMP->preferences, (or sometimes in another OS, file->preferences). The preferences dialogue should appear. Then in the left-hand menu of the new dialogue, expand the icon/item labelled 'folders' and look for the item named 'patterns'. Once you click on this, you should be able to find all of the folders GIMP is looking for patterns in, as shown in the following screenshot.

    Saturday, 10 November 2012

    Batch resize images to a fixed width and add watermarks

    Problem:

    I've got a bunch of images that I want to make a resized version of to post online. Additionally, I want to add a watermark to each of these resized images. I already have ImageMagick installed in my OS X or Linux computer.

    Solution:

    This is quite a specific problem with a very specific solution. This post assumes that you have read and understood the previous post found here. If not, the solution in this blog post should still be somewhat clear, if not a little fast-paced.

    For the sake of this post, let's assume that the source images are a bunch of .JPG images. Additionally, let's assume that we want to resize our images to a width of 320 pixels while maintaining the aspect ratio of the original image. Finally, let's assume that we want to give our images the semi-transparent watermark "grammarofdev.blogspot.com", using the font located at "/Library/Fonts/Arial.ttf". To prevent overriding our original images, we will also create a new sub-folder called 'results'. Below is an example Terminal command of how to do all of this (with line-breaks added for legibility):

    $ mkdir ./results
    $ mogrify -font /Library/Fonts/Arial.ttf -pointsize 88 -verbose
              -draw "fill rgba(255,255,255,0.5) text 24,75
                     'grammarofdev.blogspot.com'"
              -path ./results -resize 320 -quality 86 -format jpg *.JPG
    
    

    Phew, what an ugly, long command. What does it all mean?

    The "-font /Library/Fonts/Arial.ttf -pointsize 88" selects the Arial TrueType font with a point-size of 88pt. The "-verbose" flag outputs verbose information to the terminal while the conversion is being done. The "-draw "fill rgba(255,255,255,0.5) text 30,80 'grammarofdev.blogspot.com'"" portion tells ImageMagick to render the text "grammarofdev.blogspot.com" with a fill colour of white and an alpha of 0.5, starting at the (x,y) coordinate of (24,75) of the original image.

    The "-path ./results" indicates that the resized images should be written to the "results" sub-folder. Note that all files in that sub-folder with the same name will be written over without warning! Additionally, omitting this flag will write over all of your original images!

    Next, "-resize 320 -quality 86 -format jpg" indicates that the images should be resized to have a width of 320 pixels, maintaining the original aspect-ratio, and then converted to jpeg with a quality of 86. Finally "*.JPG" indicates that this command should convert all images with the suffix .JPG (case-sensitive).

    Note that the text is drawn onto the original image prior to the image being scaled down to the final desired size.

    Let's see how well this worked. The following two images will show an image before this command is run, and the resulting image afterwards. Note that the original image dimensions are 3264x2448 pixels, however this image is not included in this post. (A slightly-larger version can be found here!)

    Original image (scaled to width 300px):

    Watermarked image:

    Where can this be useful:

    Imagine that you had a hundred images you wanted to automatically watermark and resize, or imagine that you have created a web app that requires re-sizing and watermarking previews of images. Using ImageMagick to perform this task is a quick way to achieve the desired results without needing to program anything complex, or use programs such as Photoshop. This post only touched the surface of what ImageMagick can do. For more details on resizing, or details on drawing on images automatically with ImageMagick, check out the following references.


    References:

    OS X Terminal says 'you have mail'

    Problem:

    Whenever I open OS X Terminal, it says "you have mail". Why is this, and how can I get rid of this message?

    Explanation:

    OS X machines, just like Linux and Unix machines, have the capability to send emails to other machines, as well as receive emails from other machines directly to and from your local machine's user account. Long story short, if you are seeing the "you have mail" message in your Terminal window, your computer's local SMTP server has somehow received an email message to your account. (For far more details, look at the references below, or Google the terms "postfix", "sendmail", and "OS X").

    Solution (using Terminal only):

    This solution solely uses the Terminal. If you are not comfortable with this, please do not follow the rest of this how-to as you can cause some serious damage to your system if you don't know what you're doing. If you'd still like to poke around your system, try the "partially without Terminal" solution below.

    The mail received in your account is saved in the file "/var/mail/$USER", where $USER is the name of your account. For instance, if your account was named "someone", and if your home folder shows up in the OS X filesystem as "/Users/someone", then the mail on your machine has been stored in "/var/mail/someone".

    Because this is a regular text file, you can simply open it in a text editor to read the mail stored in this file, or you can view the file's contents directly in the Terminal with the command "more /var/mail/$USER", replacing "$USER" with your username (although typing in the command exactly will also suffice in this case, as Terminal will replace $USER with your username).

    To get rid of the "you have mail" message, simply move or delete the email file from /var/mail. For instance, assuming again that your account name is "someone", you can type into the terminal "sudo rm -i /var/mail/someone", then confirm deletion when prompted. This command is permanent and possibly destructive if done wrong, so do not make any typos.

    Finally, if you have reason to believe that something unusual is sending out emails from your machine after looking at your email file in /var/mail, you can check out the mail log on your machine with the command "more /var/log/mail.log" to see what email activity has occurred on your machine.

    Solution (partially without Terminal):

    To view the local mail folder on your OS X system in the Finder, type the following command into the Terminal window:

    open /var/mail

    Once open in the finder, to view the mail on your local machine, open the text file that matches your user in the "/var/mail" folder. For instance, if your username is "someone" and your home folder is "/Users/someone", then the email file to open is "/var/mail/someone".

    With the OS X Finder still open to the "/var/mail" folder, in order to remove the "you have mail" message from the Terminal move the email text file from the "/var/mail" folder, or delete it altogether. For instance, if your user is "someone", you will want to either move or delete the file "/var/mail/someone".

    After reading your email, if you suspect that there is unusual email activity happening on your local machine, you can confirm this by looking at the machine's email log with the following Terminal command:

    open /var/log/mail.log

    References:

    Friday, 14 September 2012

    Count the number of lines in a file using terminal

    Problem:

    I would like to count the number of lines in a file.

    Solution:

    An easy way to count the number of lines in a file in Linux or OS X is to use the 'wc' command in terminal. For instance:

    cat myfile.txt | wc -l 
    

    Reference:

    The 'wc' command can also do a bunch of other useful things. You can find out more by googling, looking at the command's man page, or clicking the following reference: http://linux.about.com/library/cmd/blcmdl1_wc.htm