# Opinionated guide to DrRacket scripts

**URL:** <https://racket.discourse.group/t/opinionated-guide-to-drracket-scripts/2552>\
**Category:** Show & Tell\
**Tags:** drracket, quickscript\
**Created:** [November 29, 2023, 11:30pm UTC](https://racket.discourse.group/t/opinionated-guide-to-drracket-scripts/2552 "2023-11-29T23:30:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spdegabrielle](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/spdegabrielle/32/95_2.png) [@spdegabrielle](https://racket.discourse.group/u/spdegabrielle)\
**Post date:** [November 29, 2023, 11:30pm UTC](https://racket.discourse.group/t/opinionated-guide-to-drracket-scripts/2552/1 "2023-11-29T23:30:04Z")

</div>

DrRacket has many great features, but one of my favourites the script capability that allows you to quickly and easily extend DrRacket. The scripts are immediately accessible and - _this is the best part_ - DrRacket is scripted in Racket!

Here is a quick example: **Open terminal here** :

```scheme
#lang racket/base
(require racket/system
         racket/path
         quickscript)

(script-help-string "Open a terminal in the directory of the current file.")

(define-script open-terminal
  #:label "Open terminal here"
  #:menu-path ("&Utils")
  #:os-types (unix macosx windows)
  (λ (str #:file f)
    (unless f
      (set! f (current-directory)))
    (define dir (path->string (path-only f)))
    (case (system-type 'os)
      [(unix)
       (system (string-append "gnome-terminal"
                              " --working-directory=\"" dir "\""
                              " -t \"" dir "\""
                              "&"))]
      [(macosx)
       (system
        (string-append "osascript -e 'tell app \"Terminal\" to do script \"cd \\\"" dir "\\\"\"'" ))]
      [(windows)
       (shell-execute #f "cmd.exe" "" dir 'sw_shownormal)])
    #false))

```

This script opens a command line / terminal session in the folder of the file in the currently selected tab.

In windows the menu looks like this:

![unnamed](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/4/4f3d6d0c54143b40847f37d2e5645a3dbf676041.png)

Menus are ok, but I want a keybinding! keybindings are fast and I want to be _fast_!

Lets get started:

1. click on 'quickscript' in the require and press the F1 key - DrRacket opens a local copy of the documentation to a search  
 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/4/412280ea848eb5ba20c1a8a9f87e9b0ebf40b12e.png)  

2. click on 'Quickscript' for the full documentation  

3. I'll add the `#:shortcut` `#:shortcut-prefix` keywords so I can press `[option]`-`[t]` to open the command line:

```scheme
(define-script open-terminal
  #:label "Open terminal here"
  #:menu-path ("&Utils")
  #:shortcut #\t
  #:shortcut-prefix (option)
  #:os-types (unix macosx windows)
  (λ (str #:file f)
  ...

```

1. Save, then click `Scripts`\>`Compile scripts`  
 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/e/e8db660f66c5146853e300cd94417cf8ec560a2e.jpeg)

Now I can click `[option]`-`[t]`, and my command line opens!

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/7/7ee7c68b15c5d70270dd71153f755b63544f4829.jpeg)

The DrRacket plugin that makes this all possible is Quickscript, and it was created by @Laurent.O.  
You don't need to install it as it is included when you download the Racket installer.

In addition to making your own scripts there is a nice set of scripts in the [`quickscripts-extra` package](https://pkgs.racket-lang.org/package/quickscript-extra), with more listed on the Racket wiki at [https://github.com/racket/racket/wiki/Quickscript-Scripts-for-DrRacket](https://github.com/racket/racket/wiki/Quickscript-Scripts-for-DrRacket).

I'd very much like to see what scripts you make.

Best regards

Stephen :beetle:

PS I didn't write **Open terminal here** - it was written by @Laurent.O but thanks also to @bdeket and [@soapdog](https://github.com/soapdog) for working out the windows and linux specific calls. I'm sorry I can't remember who helped me with _osascript_ - but thank you too.
