Showing posts with label Terminal. Show all posts
Showing posts with label Terminal. 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:

Friday, 1 June 2018

How to fix kernel_require.rb:55:in `require': cannot load such file -- xcodeproj (LoadError)

Problem:

When I try to build and deploy in XCode 9.3, I get the following error related to: "kernel_require.rb:55:in `require': cannot load such file -- xcodeproj (LoadError)"

/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- xcodeproj (LoadError)
 from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
 from /Development/ELD.iOS/ELD/Scripts/generate_resources.rb:4:in `
' Command /bin/sh failed with exit code 1

Possible solutions to try:

There are several possible ways to address this issue. Two are listed here to try.

  1. Install XCode command line tools from Apple
  2. Install the gem "xcodeproj"

To install XCode command line tools...

  1. Go to https://developer.apple.com/download/more/ and login
  2. Search for the command line tools for your version of XCode, download it, then install it.

To instead install the gem "xcodeproj"...

  1. Open a Terminal window
  2. Use the command:
    sudo gem install xcodeproj

Notes:

This how-to was tested to work for a project on macOS High Sierra 10.13.4 and XCode 9.3. Your results may vary. It assumes a little working knowledge of XCode and Terminal.

Best of luck!

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:

  • How to change Ubuntu timezone to UTC

    Problem:

    How can I change my timezone to UTC in Ubuntu?

    Solution:

    1. In a terminal window type:
      sudo dpkg-reconfigure tzdata
      
    2. Then select "None of the above":
    3. After that, select "UTC":

    If all goes well then the "date" command should show the date and time in UTC.

    References:

    Friday, 17 November 2017

    Run gpsfeed+ in Lubuntu 16.04

    Problem:

    I would like to run gpsfeed+ in Lubuntu 16.04.

    I am running Lubuntu in VirtualBox. I want to output to guest COM1, and send this feed to a physical serial port on COM6 on my host machine.

    Solution:

    To run first time:
    1. download the gpsfeed+.tcl script
    2. open terminal
    3. install "wish" (in terminal: sudo apt-get install tk)
    4. install "libudp-tcl" (in terminal: sudo apt-get install libudp-tcl)
    5. (in terminal, navigate to folder where gpsfeed+.tcl script is)
    6. run gpsfeed+.tcl script (in terminal: wish gpsfeed+.tcl)

    To output to COM1 in Lubuntu VirtualBox guest:

    1. open VirtualBox settings for your guest machine
    2. navigate to "serial ports" and enable COM1
    3. to send the guest COM1 to a host serial port, configure port mode to send to host (for instance, to pipe to COM6 on a Windows host, use the settings in the screenshot below)
    4. in gpsfeed+: go to Connection->Serial/IP, and set Port to "/dev/ttyS0" (see this stack exchange question on how to find your serial ports in Linux)
    5. if needed, you may need to give read/write privileges to ttyS0 in terminal (make sure you know the implications first, or google them). One way is to add your user to the dialout group: "sudo usermod -G dialout -a (your username here)"
    6. if all works then you should see the NMEA sentences being sent to your serial port after starting the simulation in gpsfeed+
    VirtualBox settings to enable COM1 in guest and send to COM6 on host:
    Gpsfeed+ setting to send to COM1 in VirtualBox Lubuntu:

    Notes:

    These instructions were found to work using a Windows 10 host, VirtualBox 5.1.30, Lubuntu 16.04.1 32-bit, and gpsfeed+ v0.58. A physical serial port exists on COM6 on the host machine. With other settings, your mileage may vary.

    References:

    Wednesday, 4 January 2017

    Android screenshot to computer with adb

    Problem:

    How do I use adb to get a screenshot from an Android device or emulator?

    I'd like to target a specific device when more than one are connected to adb.

    I already know how to open adb shell and put a device in debugging mode.

    Solution:

    One method is the following:

    1. Get list of devices:
      adb devices -l
      

      You should get a list that looks like:

    2. Once you have a device identifier, such as "emulator-5554", you can use similar commands as below. (Replace "emulator-5554" with your device identifier).
      adb -s emulator-5554 shell screencap -p /sdcard/screencap.png
      adb -s emulator-5554 pull /sdcard/screencap.png
      
    3. (Optional) remove the last screencap from your device (in this example, named "emulator-5554"):
      adb -s emulator-5554 shell rm /sdcard/screencap.png
      

    Other notes:

    If you've only got one device accessible to adb, you can simply do the following:

    adb shell screencap -p /sdcard/screencap.png
    adb pull /sdcard/screencap.png
    adb shell rm /sdcard/screencap.png
    

    If you'd like to see a one-liner to do the above, check out the neat example here: http://blog.shvetsov.com/2013/02/grab-android-screenshot-to-computer-via.html

    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:

    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.)

    Tuesday, 22 January 2013

    Some useful postfix commands

    Intro

    This is a partial list of useful commands related to postfix/sendmail for my own reference. It's posted here in case anyone else finds this useful, too.

    Commands

    • List stuff in the mail queue:
      mailq

    • Read a message in the mail queue with example id 012345678F:
      postcat -q 012345678F

    • Delete a message in the mail queue with example id 012345678F:
      postsuper -d 012345678F

    • Delete ALL messages in the mail queue (warning - no confirmation nor undo!):
      postsuper -d ALL

    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

    Replace spaces with newlines using terminal

    problem:

    Using Linux or OS X, I would like to replace spaces with newline characters in a file and output the result to a new file.

    For instance, if my file's contents look like the following:
    Monday Tuesday Wednesday Thursday Friday

    The output should look like:
    Monday
    Tuesday
    Wednesday
    Thursday
    Friday

    solution:

    In the terminal, a simple solution would be to use the 'tr' command, for instance:
    cat infile.txt | xargs | tr -s ' ' '\n' > outfile.txt
    

    reference:

    http://www.linfo.org/tr.html

    Sunday, 13 May 2012

    Copy files in order using Linux or OS X

    Problem:

    How do I copy files in sorted order using the Linux or OS X Terminal?

    Solution:

    In the terminal, you can use a combination of the "find", "sort", "xargs", and "cp" commands to copy files in sorted order.

    For instance, first switch to the directory that has the files you would like to copy:

    cd /path/to/media/directory
    

    Then copy the files in sorted order:

    find . -print0 | sort -z | xargs -0 cp --parents
      --target-directory=/path/to/destination -v
    

    Note that the above command is a single line, (but it appears split into two in order to fit into this page.)

    In the cp command, the -v flag will help you see if files are being copied in the desired order. This can be omitted if you do not wish to monitor the files being copied. To customize the order of your sort, simply customize the flags used with the 'sort' command (see the manual pages for 'sort' using the command 'man sort', if you're unsure of how to do this).

    Why copying files in sorted order can be useful:

    Some MP3 players, digital media players, and other devices play back media in the order that files were copied to it. With some file managers, files can be copied out of order, in reverse-sorted order, or in other ways that copy files out of the order that is desired (such as copying multiple files in parallel). There are also other situations where copying files in a particular sorted order would be useful. For instance, copying files in some required order to a custom-built robot's flash memory, etc.

    Other thoughts:

    Although the command 'cp -R' can also recursively copy things in order, the method mentioned above in this post should give a bit more flexibility customizing the sorted order of the copied files.

    Friday, 2 March 2012

    gedit something in OS X terminal

    Trying out OS X after using Ubuntu, I often found myself typing into the terminal "gedit <something>" to do a quick edit of a file, which didn't work out of the box. If you're here and you also didn't want to give up that old habit, here's one way to get that terminal command to work again. (I got this to work with gedit 3.2.6 under OS X 10.7.3, so your mileage might vary with other setups...)

    1) install the gedit app
    (This can be found at their project page: http://projects.gnome.org/gedit/

    Caution: if you don't know what "sudo" is, how to write shell scripts, or what file permissions are, read up on it before doing the next few steps or you could potentially screw up your system.
     
    2) create a shell script named 'gedit' in a folder defined in your PATH (in my case, I just put it in /usr/bin), and have it open a file using gedit

    In the terminal, create a new shell script named 'gedit' using a text editor. In this example we use the 'nano' text editor.

    sudo nano /usr/bin/gedit

    Type in the following script:
    #!/bin/bash

    open -a /Applications/gedit.app/Contents/MacOS/gedit $1


    Save.


    This lets you do simple "gedit something.txt" or "gedit" commands from the terminal. You can change this script as you desire for more complicated behavior.


    3) make the script executable
    sudo chmod +x /usr/bin/gedit


    To test if this worked out, open up a file using gedit in the terminal, e.g. "gedit myfavoritefile.txt"


    4) how to undo this
    To undo all of this, simply delete the /usr/bin/gedit script you created and uninstall gedit.