Mac OS: App Translocation and Android Studio updates failure

I installed Android Studio via homebrew “brew cask install android-studio” as a part of my automated Mac OS setup. Recently, Android Studio prompted me that an update is available. When I accepted to update, it failed with an error “Studio does not have write access to /private/var/folders/wt/rjv6_wcn4f97_2nth7fqftqh0000gn/T/AppTranslocation/19A80F28-865B-41FC-AA87-B8E43C826FCB/d/Android Studio.app/Contents. Please run it by a privileged user to update.” This error was confusing; I was running Android Studio as myself, a nonprivileged user and the same user owned this directory. Googling it a bit for AppTranslocation took me here.

From this point onward, the issue and the fix were relatively straightforward. Apple marked Android Studio as quarantine and hence was in a read-only directory. Quarantine status was confirmed by

$ xattr -l /Applications/Android\ Studio.app/
com.apple.quarantine: 00c1;5ad6b178;Chrome;9B843802-B7C1-4F48-BC68-09D8F81E6784

The fix was relatively simple as well

$ xattr -d -r -s com.apple.quarantine /Applications/Android\ Studio.app/

Update worked as expected after this.

Setting HOMEBREW_CASK_OPTS=–no-quarantine seems to enable this behavior for all the future installs.

Diagnosing Mac apps which won’t open (error -10810)

Occasionally, my mac applications end up in a corrupt state where they won’t open. I recently encountered this with Deluge. The first step to diagnose is to open Terminal and open them in the terminal via

$ open -a deluge  # This name is same as the name of the app (minus the ".app" portion).
LSOpenURLsWithRole() failed for the application /usr/local/Caskroom/deluge/1.3.12/Deluge.app with error -10810.

Now, the error is more diagnosable but still cryptic. Deluge.app above is a directory and we can navigate to the binary located at Deluge.app/Contents/MacOS/Deluge and execute the actual binary to see a more actionable error

$ /usr/local/Caskroom/deluge/1.3.12/Deluge.app/Contents/MacOS/Deluge
Traceback (most recent call last):
  File "/usr/local/Caskroom/deluge/1.3.12/Deluge.app/Contents/MacOS/Deluge-bin", line 5, in <module>
    from pkg_resources import load_entry_point
  File "pkg_resources/__init__.pyc", line 37, in <module>
  File "email/parser.pyc", line 12, in <module>
  File "email/feedparser.pyc", line 27, in <module>
  File "email/message.pyc", line 16, in <module>
  File "email/charset.pyc", line 13, in <module>
  File "email/base64mime.pyc", line 40, in <module>
  File "email/utils.pyc", line 29, in <module>
  File "urllib.pyc", line 1414, in <module>

ImportError: dlopen(/usr/local/Caskroom/deluge/1.3.12/Deluge.app/Contents/Resources/lib/python/lib-dynload/_scproxy.so, 2): Symbol not found: _inflateValidate
  Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libPng.dylib
  Expected in: /usr/local/Caskroom/deluge/1.3.12/Deluge.app/Contents/Resources/lib/libz.1.dylib
 in /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libPng.dylib

Now, this is something meaningful and Google search worthy. Googling for “Symbol not found: _inflateValidate” takes us to the most likely cause. In my case, uninstall followed by the reinstall of Deluge fixed it.

Mac OS X Primer (Part 3) – Window Management

Default window management scheme in Mac OS X is not well-polished. For example, there is no way to make an application occupy left half of the screen or to make an application always stay on top. To improve on that, my personal setup includes following applications.

  1. Better Touch Tool – At the most basic level, it provides “Window snapping” feature, drag the window to top-left and it expands to full screen. It allows full control of gestures and keyboard shortcuts. My personal setup includes “cmd + option + Tab” to switch between active windows of the same application. It is available via homebrew cask.
    brew cask install bettertouchtool
  2. Spectacle  – Spectacle allows quick resizing and shifting of windows. For example, Cmd + option + right/top/left/down arrow key will make the currently focused application occupy right/top/left/bottom half of the screen, respectively. AmeythstDivvy or Moom are popular alternatives to Spectacle, an even bigger list can be seen here. Spectacle is available via homebrew as well. 
    brew cask install spectacle
  3. Afloat – To keep a window floating on top of other windows. Unfortunately, setting this up is a bit convoluted and is not guaranteed to work. Following approach worked for me.
    This approach is based on findings of Ankur Gupta and Norio Nomura.

    1. Install SIMBL
      1. Download SIMBL 0.9.9.
      2. Extract the downloaded archive and run the .pkg installer file. You may need to go to System Preferences > Security & Privacy to allow running the installer.
      3. Finish installation of SIMBL.
    2. git clone https://github.com/rinckd/afloat
      cd afloat 
      xcodebuild GCC_ENABLE_OBJC_GC=unsupported -configuration Release
      cp -r build/Release/Afloat.bundle* /Library/Application Support/SIMBL/Plugins/
      
    3. Use an Applescript to start afloat automatically on start as described here.
    4. afloat will work for all the apps started after afloat has been injected.