News for hackers. Stuff that matters.
Re:Useful built-in macOS command-line utilities by vbezhenar on Wednesday November 06, 2024 @03:24AM (#42058069)
Few additions.

open -n file.pdf : opens new instance of Preview application which is useful if you want to open the same file twice (for example to look at different pages at once).

caffeinate -d : prevents display turning off, useful if you want to look at display without moving mouse.

Re:Useful built-in macOS command-line utilities by wwader on Wednesday November 06, 2024 @03:39AM (#42058131)
open -a is nice, i use it with alias, ex:

  alias qt='open -a "quicktime player"'
  alias vlc='open -a "vlc"'
Re:Useful built-in macOS command-line utilities by FabHK on Wednesday November 06, 2024 @11:04AM (#42064357)
At least for me (I've installed vlc via homebrew), there is a vlc binary in the PATH, and I can just vlc <filename>
Re:Useful built-in macOS command-line utilities by qrios on Wednesday November 06, 2024 @01:24PM (#42066842)
The point here is to open a document with an app not assigned as default for the given mime-type by file name extension.
Re:Useful built-in macOS command-line utilities by mjs on Wednesday November 06, 2024 @05:33AM (#42059558)
Does `open` give focus? It used to, but since a few releases ago the app opens in the background, which is pretty annoying.

My poor workaround is to use osascript: `tell application "System Events" to set frontmost of process "Finder" to true`

Re:Useful built-in macOS command-line utilities by masswerk on Wednesday November 06, 2024 @06:57AM (#42060712)
Apparently, it does. There is a -g flag (background) to prevent focus.
Re:Useful built-in macOS command-line utilities by justletmein on Wednesday November 06, 2024 @03:31PM (#42068883)
Isn’t open opening apps in the background a consequence of having “secure keyboard entry” enabled in Terminal.app?
Re:Useful built-in macOS command-line utilities by troupo on Wednesday November 06, 2024 @05:41AM (#42059666)
`caffeinate -disu` is the best combination (that is, enable all options): your laptop won't go to sleep, won't dim the screem etc.
Re:Useful built-in macOS command-line utilities by 1ncorrect on Wednesday November 06, 2024 @07:08AM (#42060870)
I use this all the time:

open -a <GUI Application> <File>

Handy for distinguishing between editing and consuming media.

Re:Useful built-in macOS command-line utilities by alsetmusic on Wednesday November 06, 2024 @09:30AM (#42062814)
Also, `cd .` to open the current directory in a Finder window.

Not mine (found online years ago), but here's the opposite. `cd` into the frontmost Finder window:

  cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')";
Re:Useful built-in macOS command-line utilities by kps on Wednesday November 06, 2024 @09:32AM (#42062836)
You mean `open .`
Re:Useful built-in macOS command-line utilities by alsetmusic on Wednesday November 06, 2024 @03:32PM (#42068896)
Yeah, I had just woke up. Drat.
Re:Useful built-in macOS command-line utilities by sneak on Wednesday November 06, 2024 @11:36AM (#42064862)
You can also just drag the proxy icon onto the terminal window for its path, ie “cd “ <drop>, enter.
Re:Useful built-in macOS command-line utilities by kstrauser on Wednesday November 06, 2024 @12:14PM (#42065539)
I use that all the time. You can also cmd-c copy a file in Finder then paste into the terminal to get its path.
Re:Useful built-in macOS command-line utilities by alsetmusic on Thursday November 07, 2024 @09:40AM (#42076998)
I genuinely didn't know this. I would have thought I had to do the "copy as pathname" trick with a right-click while holding Option. I already knew the drag and drop feature, so this doesn't really save me time, but it's good to know another nice feature.
Re:Useful built-in macOS command-line utilities by hk1337 on Wednesday November 06, 2024 @10:44AM (#42064032)
open -a "Finder" . - open Finder in the current directory.

Standard apps usually just need the name, like Finder and Safari but you can also specify the path "/Applications/DifferentFinder.app"

Re:Useful built-in macOS command-line utilities by ssttoo on Wednesday November 06, 2024 @10:57AM (#42064242)
`open .` works for me too
Re:Useful built-in macOS command-line utilities by hk1337 on Wednesday November 06, 2024 @11:08AM (#42064415)
Yeah, I scrolled a bit and noticed that. Never thought about using just that.
Re:Useful built-in macOS command-line utilities by 1-more on Thursday November 07, 2024 @11:37AM (#42078197)
Also `open -R path/to/file` opens Finder in the containing directory with the file highlighted (and thus scrolled into view). I use this with a script that takes a screen recording and trims some specified seconds off the end and converts it to mp4 to be smaller when I upload into a Github PR description. Easiest to drag and drop the converted file, y'see.
Re:Useful built-in macOS command-line utilities by nextos on Wednesday November 06, 2024 @12:32PM (#42065860)
Finder is pretty good, and it's handy to be able to open it from the terminal. But I find it super annoying it litters everything with .DS_Store files and there is no way to turn that off, except for external and network drives. Aside from, obviously, using a different file manager. Very un-Apple.
Re:Useful built-in macOS command-line utilities by seec on Wednesday November 06, 2024 @03:37PM (#42068957)
Well those files are to keep the view/presentation settings.

I guess you could do that centrally with some sort of database but that would open another can of worms; and most importantly you wouldn't be able to transfer a folder and keep its Finder presentation intact.

Nowadays it's not as useful because of the App Store but when software was only released as .dmg images, it became expected to open a nice layout with graphics presenting the app and a shortcut to the App folder that you would drag'n'drop the app bundle to.

This presentation relies of .DS_Store to work.

There are some other use cases like that, it all comes down to a simple fact: Apple has always cared a lot more about how things look than Microsoft ever did, this is a perfect example.

Re:Useful built-in macOS command-line utilities by vbezhenar on Wednesday November 06, 2024 @05:37PM (#42070634)
There are extended attributes which could be used for this task.
Re:Useful built-in macOS command-line utilities by seec on Wednesday November 06, 2024 @09:09PM (#42072538)
I don't think xattr works for folders. And you still wouldn't have the fancy presentation you can get with .DS_Store with the graphics and all that jazz.

Of course, they could rethink the whole thing but the point is that it's a legacy thing and at this time it's not worth dedicating much ressource to a solve problem just to remove some mostly invisible files (on UNIXs). It's really easy to have scripts to cleanup for sharing to outside world, even some zip utilities do that automatically.

It can be annoying but it's really not a big deal, I doubt they could come up with something much better while still preserving the functionality and not making another complicated/convoluted proprietary folder format that wouldn't transfer any better to Windows...

Re:Useful built-in macOS command-line utilities by dwaite on Wednesday November 06, 2024 @03:19PM (#42068694)
The .DS_Store files are not Finder specific; Apple treats everything as a file (including folders), and it exists to supply folders and the files within them with metadata.

It is just the first time the .DS_Store file is needed is often when the folder is touched by Finder.

Re:Useful built-in macOS command-line utilities by codazoda on Wednesday November 06, 2024 @03:24PM (#42068780)
.DS_Store is also a bug. I’m not sure why it hasn’t been fixed. It’s history is quite interesting but I don’t recall where I read about it.
Re:Useful built-in macOS command-line utilities by mdean on Wednesday November 06, 2024 @03:28PM (#42068834)
Re:Useful built-in macOS command-line utilities by nutrie on Wednesday November 06, 2024 @01:26PM (#42066866)
Actually, .DS_Store is very Apple indeed (not that I care much).
Re:Useful built-in macOS command-line utilities by fragmede on Wednesday November 06, 2024 @12:34PM (#42065896)
you can just

    open .
unless you've reconfigured something else to open directories, which most people haven't.
Re:Useful built-in macOS command-line utilities by ilyagr on Wednesday November 06, 2024 @01:17PM (#42066681)
You can also `open -R file` to select that file in Finder.
Re:Useful built-in macOS command-line utilities by luckman212 on Thursday November 07, 2024 @08:03PM (#42083045)
Don't forget about "open -b <bundle_id> foo.txt" for example,

    open -b com.sublimetext.4 file.txt
I prefer this vs using the App Name or Path, since those can vary depending on the system or app version. The bundle ID is more robust.
Re:Useful built-in macOS command-line utilities by impalallama on Wednesday November 06, 2024 @03:04PM (#42068484)
caffeinate -d is incredibly useful for work... uh reasons
Re:Useful built-in macOS command-line utilities by JasserInicide on Wednesday November 06, 2024 @04:23PM (#42069639)
Jiggler is better for that at least from a set-it-and-forget-it perspective vs. caffeinate where you have to manually set it.
Re:Useful built-in macOS command-line utilities by seec on Wednesday November 06, 2024 @03:30PM (#42068855)
That's one of macOS pitfalls: the inability to open 2 instances of the same app, simply using the default GUI is annoying sometimes.

I think Windows is right in that matter...

Re:Useful built-in macOS command-line utilities by beancookies on Wednesday November 06, 2024 @04:25PM (#42069659)
Another useful caffeinate tip is the `-w` option.

You can use it to pass a pid to keep the computer awake until that process completes. I use it for longer-running scripts that I don't want interrupted

Re:Useful built-in macOS command-line utilities by justinsaccount on Thursday November 07, 2024 @08:05AM (#42076298)
That's mostly what `caffeinate your-script` is for.