Open a Folder or File in a new VS Code window on Mac OS

Problem: When opening a new folder in VS Code (Mac OS), I want it to open a new VSCode window, and not add the folder to the already open window. I’m used to the Atom IDE behaviour from years back.

Fix: There are two settings that help here:
window.openFoldersInNewWindow controls whether a folder should be opened in the same window or a new one.

window.openFilesInNewWindow does the same for Files, i.e. when you open just a single file.

These settings can be found in the ‘Code > Preferences > Settings’ menu item. OR easier still, with the shortcut  ⌘, (or ‘Command’ plus ‘comma’ keys, if you can’t see the shortcut to the left here)

Once in Settings, start typing window.openF and you should see both options there. Set one or both to on for the desired behaviour. Can’t remember if you have to restart VS Code or not after changing this. Try it!

Please let me know if this works for you Nope, not helpful...Yep, more useful than not! (No Ratings Yet)
Loading...

Splitting many files into numbered folders with leading zeros

Problem: I had a few thousand files in a directory and needed them to be in a series of numbered folders – specifically with leading zeros – with no more than 100 files in each. Don’t ask why… just some weird old batch program that needs files presented that way. Obviously manually creating directories and moving the files was going to take a while. Also, this needed to be done via a cron job, so I needed something scriptable.

Solution: Thankfully all sorts of magic can be done on the *nix command line, and we have access to very useful formatting functions like printf and for loops.

The following command achieves what I needed:

i=0; for f in *; do d=dirname_$(printf %03d $((i/100+1))); mkdir -p $d; mv "$f" $d; let i++; done

Continue reading “Splitting many files into numbered folders with leading zeros”

Get terminal / bash prompt to show useful info

Problem: Well it’s more of an irritation. My new hosting provider does allow SSH access, but when logged in the bash prompt looks like this, regardless of which account  I’m logged-in as, or where I am:

-bash-4.2$

What I want is for it to show something like:

username@server:/current/path$

Solution: The bash prompt can be customised via a profile script, ideally anything that loads when you log in like ‘.bash_profile’, ‘.bashrc’ or ‘.profile’. If one of these files doesn’t already exist in your home directory (check with ls -la ~ to list the contents) then create one. Here is an example of creating, editing and loading a login script to show a better prompt.

Continue reading “Get terminal / bash prompt to show useful info”

Using Mac Image Capture with Nikon D70 (Direct Cable connection)

Problem: Recently I dug out my old Nikon D70 to take some pics on holiday. When I connected it to my Mac (OS X v10.8.4) via the USB cable, Image Capture fired-up as expected, but when I tired to Import them I got an error stating that Image Capture was unable to import the RAW images.

Solution: It turns out that the USB mode needs to be ‘M’ now, (Mass Storage Device Mode). To set this:

  1. Press ‘Menu’ on the D70 (after disconnecting it from the Mac.
  2. On the far left of the menu, select the spanner icon to enter the ‘Settings’ sub-menu.
  3. In the Settings menu, scroll up/down to get to the ‘USB’ setting.
  4. Enter the USB setting, and set it to ‘M’ rather than ‘P’ (Picture Transfer Protocol).
  5. Reconnect the USB cable, and the images should now import ok.

Launch Google Chrome Incognito from the terminal or a shortcut in OSX

Problem: Ok not really a problem, but I want to be able to launch Google Chrome straight to Incognito mode from a shortcut. This is useful when logging into multiple bank accounts, Google Apps accounts, or testing session based websites. etc etc etc.

Fix: Thankfully the Google Chrome.app can be launched with the –incognito switch to do just that. The terminal command to do this, assuming the browser is sitting in /Applications/ is this:

open -a /Applications/Google Chrome.app --args --incognito

Note: –args has to be passed to satisfy the ‘open’ command’s arguments first.

Launching it from a shortcut: If you want to create a shortcut to do this, open AppleScript Editor and enter the following:

tell application "Terminal"
	activate
	do script "open -a /Applications/Google\ Chrome.app --args --incognito;"
	delay 1
	quit
end tell

Note: The space in the Google Chrome.app name must be double-escaped with two backslashes like that to work. Also, without the delay I found that the script exits too quickly or something like that, and it doesn’t work.

Save the above script as an Application, and call it something like ‘Incognito’. Running this app will launch Terminal, Chrome Incognito, then exit Terminal. Bingo!

Giving your Incognito app an Icon: I’ve added the app to my Dock, and given it a special icon (see below for a downloadable PNG icon). To do this:

  • Open the image you want to use as the icon – it should be a 512×512 24bit PNG if possible – and copy the image to the clipboard. If you are using Preview to view the image, do cmd+a to select all, then cmd+c to copy it… this works for most other graphics packages also.
  • Locate the app you created above in Finder, then press cmd+i to bring up the info window (alternatively right-click the app then select ‘get info’).
  • In the resulting pop-up, click on the icon at the top to highlight it like so (notice the blue halo around it):
    Original Script Icon
  • Then use cmd+v to paste the new icon from the clopboard into the icon area and it should look like this:
    New Incognito icon
  • Close the info window, and it’s done. You should now have a nice looking shortcut that opens Chrome Incognito with one or two clicks!

Feel free to use this icon. It’s just the standard one with some ‘colour replace’ work to make it blue. You could paste some tacky sun glasses over it if you wished 🙂

Batch rename file extensions from .jpg to .png in terminal

Problem: A client sent me 164 images with incorrect extensions on them. I needed to change them all from .jpg to .png.

Fix: Open up terminal, navigate to the directory containing all the images and type:

ls *.jpg | awk '{print("mv "$1" "$1)}' | sed 's/jpg/png/2' | /bin/sh

..that should do it! This one-liner makes use of sed and awk unix utilities.