The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,806 other followers

Archive for the ‘Apple’ Category

How can you export the Visual Studio Code extension list? (via: Stack Overflow)

Posted by jpluimers on 2022/06/16

Adapted from [Archive.is] How can you export the Visual Studio Code extension list? – Stack Overflow, presuming that code is on the PATH:

  1. From the command-line interface on MacOS, Linux, BSD or on Windows with git installed:
    code --list-extensions | xargs -L 1 echo code --install-extension
  2. From the command-line interface on MacOS, Linux, BSD or on Windows without git installed:
    code --list-extensions | % { "code --install-extension $_" }

    or, as I think, more clearly (see also [WayBack] syntax – What does “%” (percent) do in PowerShell? – Stack Overflow):

    code --list-extensions | foreach { "code --install-extension $_" }

    or even more explanatory:

    code --list-extensions | ForEach-Object { "code --install-extension $_" }
  3. From the command-line interface on Windows as a plain cmd.exe command:
    @for /f %l in ('code --list-extensions') do @echo code --install-extension %l
  4. On Windows as a plain cmd.exe batch file (in a .bat/.cmd script):
    @for /f %%l in ('code --list-extensions') do @echo code --install-extension %%l
  5. The above two on Windows can also be done using PowerShell:
    PowerShell -Command "code --list-extensions | % { """""code --install-extension $_""""" }"

    Note that here too, the % can be expanded into foreach or ForEach-Object for clarity.

All of the above prepend “code --install-extension ” (note the trailing space) before each installed Visual Studio Code extension.

They all give you a list like this which you can execute on any machine having Visual Studio Code installed and its code on the PATH, and a working internet connection:

code --install-extension DavidAnson.vscode-markdownlint
code --install-extension ms-vscode.powershell
code --install-extension yzhang.markdown-all-in-onex

(This is about the minimum install for me to edit markdown documents and do useful things with PowerShell).

Of course you can pipe these to a text-file script to execute them later on.

The double-quote escaping is based on [Wayback/Archive.is] How to escape PowerShell double quotes from a .bat file – Stack Overflow:

you need to escape the " on the command line, inside a double quoted string. From my testing, the only thing that seems to work is quadruple double quotes """" inside the quoted parameter:

powershell.exe -command "echo '""""X""""'"

Via: [Archive.is] how to save your visual studio code extension list – Google Search

–jeroen

Posted in *nix, *nix-tools, .NET, bash, Batch-Files, CommandLine, Console (command prompt window), Development, Mac OS X / OS X / MacOS, Power User, PowerShell, PowerShell, Software Development, Visual Studio and tools, vscode Visual Studio Code, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Development, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server 2016, WSL Windows Subsystem for Linux, xargs | Leave a Comment »

MacOS: default PCL printer driver only allows monochrome (black&white/grayscale); default PostScript allows colour

Posted by jpluimers on 2022/05/23

Printing on MacOS can be less Plug&Play than one hopes for.

For default printer drivers on MacOS for the same printer:

  • Postscript allows colour and monochrome (black & white / grayscale)
  • PCL only allows monochrome (black & white / grayscale)

One solution for my OKI MC363 is to use the HP PCL driver and fake it as a HP Colour LaserJet 9500 (which provides a similar amount of memory, and colour duplex A4 printing):

Read the rest of this entry »

Posted in Apple, Development, EPS/PostScript, Hardware, Mac OS X / OS X / MacOS, MC342 printer/scanner, OKI C332, OKI MC363/MC363DNW, OKI Printers, Power User, Printers | Leave a Comment »

How to view the html page source of a website in Safari – Macintosh How To

Posted by jpluimers on 2022/04/14

[Wayback] How to view the html page source of a website in Safari – Macintosh How To

You can enable the extra menu in Safari by selecting ‘Preferences’ under Safari in the OS X menu bar  and then under the ‘Advanced’ pane select the checkbox that says ‘Show Develop menu in menu bar.’

This is the option you need:

a

MacOS - Safari - Show Develop menu in menu bar

MacOS – Safari – Show Develop menu in menu bar

–jeroen

Posted in Apple, Development, Mac OS X / OS X / MacOS, Power User, Safari, Software Development, Web Browsers, Web Development | Leave a Comment »

Kris on Twitter is a bit radical against shell scripts. Learn why.

Posted by jpluimers on 2022/04/13

I say to people: only use shell interactively, don’t write scripts. Never. Not one.
But Kris, they ask, why so radical?
Because of this:

is the literal English Google Translation of the German text

Ich sage den Leuten: benutzt Shell nur interaktiv, schreibt keine Scripte. Nie. Nicht eines.
Aber Kris, fragen sie, wieso so Radikal?
Deswegen:

then links to [Wayback/Archive] Jan Schaumann on Twitter: “TIL zgrep(1) is a shell script. BSD basically does “zcat | grep”, but GNU does “gzip -dc | sed”. How did I learn that? The fun way! CVE-2022-1271, arbitrary-file-write and code execution vulnerability in GNU zgrep / gzip. …”:

Read the rest of this entry »

Posted in *nix, *nix-tools, Apple, ash/dash, ash/dash development, bash, bash, BSD, Development, Mac, Mac OS X / OS X / MacOS, Power User, Scripting, Software Development | Leave a Comment »

Figuring out which processes are preventing to eject/unmount my MacOS Time Machine backup USB drive

Posted by jpluimers on 2022/03/31

One day, a MacOS Time Machine backup USB drive could not me ejected/unmount.

These links helped me figure out what was wrong via [Wayback] find which macos program prevents unmount – Google Search:

  • [Wayback] macos – The volume can’t be ejected because it’s currently in use – Ask Different (Thanks [Wayback] CousinCocaine, [Wayback] Paul Gilfedder and [Wayback] Alan W. Smith)

    Q:

    • The volume can’t be ejected because it’s currently in use.
    • The disk “Diskname” wasn’t ejected because one or more programs may be using it.“.
    • umount(/Volumes/Diskname): Resource busy -- try 'diskutil unmount'

    My question: How do I know what program is using my drive so I can properly quit that program and eject my drive?

    The volume can't be ejected because it's currently in use. The disk "Camel" wasn't ejected because one or more programs may be using it. The disk "Mammtoh" wasn't ejected because one or more programs... xkcd

    A:

    lsof is indeed your best bet. The fastest and easiest way would be this :-

    sudo lsof /Volumes/myDrive
    

    It can take a couple minutes to run, but once it’s complete, it gives you a list of open files on the disk. The output will look something like this:

    COMMAND    PID  USER   FD   TYPE DEVICE SIZE/OFF  NODE NAME
    mds         89  root   19r   DIR   52,3      432     2 /Volumes/Photos
    mds         89  root   23r   DIR   52,3      432     2 /Volumes/Photos
    Finder     681 alans   14r   DIR   52,3      432     2 /Volumes/Photos
    QuickLook 2158 alans    9r   REG   52,3  1141591 78651 /Volumes/Photos/_tmp_iphone_10_backup/APC_1546.JPG  
    

    In this case, it’s the QuickLook application that has a file open. Closing the application directly is the best way to fix the issue. However, that’s not always possible. For example, QuickLook doesn’t show up as an application you can get to in the Dock.

    If you can’t close the application manually, you can use the kill command to terminate it from the command line. To do that, use the PID from the second column as the ID to kill. From the above example, it would be:

    kill 2158
    

    Note that sometimes that doesn’t work and a more aggressive form of kill must be used. Here’s a series of escalating aggressiveness (using the example PID of 2158):

    kill 2158
    sudo kill 2158
    sudo kill -INT 2158
    sudo kill -KILL 2158
    

    You should be able to eject the disk once the process/application has been killed.

    One final note, lsof can take a minute or two. It can also hang, but you should give it at least a few minutes before you decide that’s what happened.

    Also, sometimes the base command sudo lsof /Volumes/myDrive won’t find anything. If that happens, try adding the +D argument (i.e. sudo lsof +D /Volumes/myDrive). That will do a top down scan of the disk. It’ll take longer, but it should pick up anything that’s causing the disk to be un-ejectable.

    (Hat tip to Alec Jacobson’s post for extra details.)

    C:

    sudo lsof /Volumes/drive is much faster than sudo lsof | grep /Volumes/drive

  • [Wayback] Find out which application is using external hard drive in order to eject it « Alec’s Web Log
    sudo lsof +D "/Volumes/[name of drive]"

    You can always run the lsof command again to see if the process really died.

    kill [PID of process]
    sudo kill [PID of process]
    sudo kill -INT [PID of process]
    sudo kill -KILL [PID of process]
  • [Wayback] time machine – How do I make Spotlight stop indexing my Backup drive? – Ask Different (thanks [Wayback] hectorpal!)

    I finally found you cannot disable Spotlight to index Backups.backupdb.

    [Wayback] Apple Support. OS X El Capitan: Spotlight preferences

    If you add a Time Machine backup disk to the privacy list, you will continue to see messages that Spotlight is indexing your backup disk. This indexing is necessary for Time Machine to function properly and can’t be disabled. Spotlight does exclude from searches any items you store on your backup disk that are not part of a Time Machine backup.

  • [Wayback] If you can’t eject a disk from Mac – Apple Support

    If you can’t eject an external disk or storage device

    1. On your Mac, choose Apple menu  > Log Out, then log in again. Try to eject the disk again.
    2. If you still can’t eject the disk, choose Apple menu  > Shut Down. Disconnect the disk from your computer, then start up your computer again.

This figured out which processes were involved:

# sudo su -

# lsof +D /Volumes/Samsumg860Evo4TB

The main processes keeping file handles in use on the SSD device where mds and mds_stores (similar as in [Wayback] How to fix: The volume can’t be ejected because it’s currently in use). Killing spotlight did not help, and logoff failed as well: I had to shutdown the whole machine to be able to detach the USB drive.

So it was Spotlight galore all over again, which is odd, as this is a USB3 SSD for which the Time Machine backup had tried to update for more than 12 hours, so Spotlight – if indexing at all – should have been long done.

Spotlight galore:

The final solution was to perform a shutdown of the machine. It had not been for over 3 months, so apparently that caused some confusion for the combination of Spotlight and Time Machine.

–jeroen

Posted in Apple, Mac OS X / OS X / MacOS, Power User, SpotLight | Leave a Comment »

 
%d bloggers like this: