# MacOS shell-\>Drr open file? (quality-of-life improvement yay! ... but then sad face)

**URL:** <https://racket.discourse.group/t/macos-shell-drr-open-file-quality-of-life-improvement-yay-but-then-sad-face/3273>\
**Category:** General\
**Created:** [October 27, 2024, 9:18pm UTC](https://racket.discourse.group/t/macos-shell-drr-open-file-quality-of-life-improvement-yay-but-then-sad-face/3273 "2024-10-27T21:18:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [October 27, 2024, 9:18pm UTC](https://racket.discourse.group/t/macos-shell-drr-open-file-quality-of-life-improvement-yay-but-then-sad-face/3273/1 "2024-10-27T21:18:41Z")

</div>

SUPER TL;DR: fix doesn't work!  
TL;DR: see fix at end!

As I chug through daily work, I realize that one serious time-saver for me would be the ability to use a shell command to open a file in DrRacket. So, for instance, I'm in a particular directory in the shell, and I want to send the `text.rkt` file to be opened by the already-running DrR instance. This has a vaguely quickscript flavor to it, but I think that doing it from the shell probably involves some

... well, let me go read the man page.

Okay, I'm back from the man page for `open`, and I'm amused by a bunch of things; it explicitly says "This behavior was also present in Tiger.". Also, it was last updated in 2017, I believe. The important piece, though, is that reading this makes it clear that the intended behavior is that if the application is already open, no new instance of the application is created. Unfortunately, the behavior I observe (I hope I'm not alone in this?

... (uh oh) ...

... does a bunch of experimentation ...

Oh! It turns out that `open` does exactly what I want, as long as the version DrRacket that's running matches the "default application" setting in the OS. You can change this by opening a finder window with a `.rkt` file, right-clicking the file, and choosing "Open With ... \> Other", then finding the correct DrRacket application in the resulting Finder window and selecting the "Always Open With" checkbox before confirming your choice. For me, this causes the `open` command in the terminal to send the file to the running DrRacket instance to be opened, and means that (for instance) opening a whole bunch of files ...

... gah! ...

ugh ugh ugh it turns out that this literally only changes the mapping for THIS ONE FILE. There's another mechanism, the Get Info box, which allows you to set an application for all files with a given extension, and actually gives you a "this is about to change the settings for all files" warning... but it still doesn't work! My guess is that this could successfully change the mapping from one application to a totally different one, but when you have multiple versions of a single application, it doesn't seem to change anything, which you can see immediately after confirming on that dialog, because the setting in the get info box goes right back (for me) to "8.14 (default)". Ugh.

Okay so this went from amazing success to miserable failure.

There's a great article from eclectic light on this:

> **[Launch Services database problems: correcting and rebuilding](https://eclecticlight.co/2017/08/11/launch-services-database-problems-correcting-and-rebuilding/)**
>
> What do you do when you open a document, only to find that the wrong app opens it? Here’s how to tackle that and more.

... but unfortunately, it doesn't give any suggestions for directly manipulating the launch services database, just rebuilding it.

---

<div class="post-metadata">

**Author:** ![robby](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/robby/32/7_2.png) [@robby](https://racket.discourse.group/u/robby)\
**Post date:** [October 27, 2024, 9:38pm UTC](https://racket.discourse.group/t/macos-shell-drr-open-file-quality-of-life-improvement-yay-but-then-sad-face/3273/2 "2024-10-27T21:38:28Z")

</div>

For me, something changed in Sonoma such that the open DrRacket wasn't the default one, so now I'm using this shell script with success:

```scheme
#!/bin/sh

open -a /Users/robby/git/exp/plt/racket/DrRacket.app/Contents/MacOS/DrRacket "$@"

```

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [October 28, 2024, 12:29am UTC](https://racket.discourse.group/t/macos-shell-drr-open-file-quality-of-life-improvement-yay-but-then-sad-face/3273/3 "2024-10-28T00:29:13Z")

</div>

oh! You can specify the application in the call to open. Of course, that's exactly the right solution, many thanks.

(FWIW, I did have success using the command  
`/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -v -apps u,s,l`  
taken from the Eclectic Light post, but there seems like a lot of "crossing your fingers and hoping" associated with this approach, yours is clearly much better.)

---

<div class="post-metadata">

**Author:** ![tinkererthinker](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/tinkererthinker/32/2108_2.png) [@tinkererthinker](https://racket.discourse.group/u/tinkererthinker)\
**Post date:** [December 30, 2024, 4:14pm UTC](https://racket.discourse.group/t/macos-shell-drr-open-file-quality-of-life-improvement-yay-but-then-sad-face/3273/4 "2024-12-30T16:14:23Z")

</div>

I'm using MacOS Sequoia and it looks like you can open racket files with DrRacket by default again in the terminal.

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [December 30, 2024, 7:48pm UTC](https://racket.discourse.group/t/macos-shell-drr-open-file-quality-of-life-improvement-yay-but-then-sad-face/3273/5 "2024-12-30T19:48:19Z")

</div>

Can you control which version it uses? This was the point on which I foundered before.

---

<div class="post-metadata">

**Author:** ![shhyou](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@shhyou](https://racket.discourse.group/u/shhyou)\
**Post date:** [December 31, 2024, 7:05am UTC](https://racket.discourse.group/t/macos-shell-drr-open-file-quality-of-life-improvement-yay-but-then-sad-face/3273/6 "2024-12-31T07:05:13Z")

</div>

Does it work if you right-click on a Racket file in Finder -\> _Get Info_ (not just Open with) -\> Select the right DrRacket under "Open with:" -\> Change All...?

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [December 31, 2024, 12:56pm UTC](https://racket.discourse.group/t/macos-shell-drr-open-file-quality-of-life-improvement-yay-but-then-sad-face/3273/7 "2024-12-31T12:56:34Z")

</div>

I believe that I tried what you're referring to, see my earlier text starting with

> [@jbclements](#):
>
> There's another mechanism, the Get Info box, w

Let me know if I'm misunderstanding you!

FWIW, I'm not actually terribly interested in working on this problem for my own personal use, Robby's shell script solution is better than depending on janky MacOS internal app databases anyway, but I understand that not everyone does all of their work in a terminal, so I'm happy to continue to experiment if it provides value for someone else.

---

<div class="post-metadata">

**Author:** ![shhyou](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@shhyou](https://racket.discourse.group/u/shhyou)\
**Post date:** [December 31, 2024, 9:31pm UTC](https://racket.discourse.group/t/macos-shell-drr-open-file-quality-of-life-improvement-yay-but-then-sad-face/3273/8 "2024-12-31T21:31:59Z")

</div>

Ah, yes, I missed that paragraph.

 ![Screenshot of Get Info of Racket](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/6/6ab9f5c3f25b78d22eb4b2950f419f94f9f17e75.jpeg)  
The "Get Info" tab shows the version of DrRacket. I seems to have encountered the same issue before. I don't remember exactly what I did, but one thing was that I tried to rename the `DrRacket.app/` folder to something like `DrRacket v83.app/` which helped Mac differentiate different DrRacket applications.
