diff options
author | Aleix Conchillo FlaquƩ <aconchillo@gmail.com> | 2022-02-04 21:43:29 -0800 |
---|---|---|
committer | Aleix Conchillo FlaquƩ <aconchillo@gmail.com> | 2022-02-04 21:43:29 -0800 |
commit | dc01c64370a8ab2dab83bb4a024feeb1727a0491 (patch) | |
tree | ecadc89dbc71d76c996d38796db620cc36828011 | |
parent | ba5e1879b584bcbc21e7cb277aae0fea0c14fe0d (diff) |
allow creating application bundles
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.org | 21 | ||||
-rwxr-xr-x | gas | 18 | ||||
-rw-r--r-- | share/guile.icns | bin | 0 -> 26745 bytes |
4 files changed, 38 insertions, 3 deletions
@@ -24,6 +24,8 @@ install: chmod +x gas install -d '$(DESTDIR)/bin' install -c gas '$(DESTDIR)/bin' + install -d '$(DESTDIR)/share/gas' + install -c share/guile.icns '$(DESTDIR)/share/gas' uninstall: rm -f '$(DESTDIR)/bin/gas' @@ -7,6 +7,8 @@ This project is in a very primitive state since it depends on GuileScript which is totally a work-in-progress. I actually started GuileScript in order to be able to create gas after seeing [[https://twitter.com/zaneshelby/status/1477988369154121734?s=20][obb]], a very cool ClojureScript project. +[[./gas.gif]] + * Installation You can clone the repo and run: @@ -23,10 +25,25 @@ $ brew install aconchillo/guile/gas * Examples -There's only one example right now: +There's only a couple of examples right now, you can try: #+BEGIN_EXAMPLE $ gas examples/choices.gs #+END_EXAMPLE -[[./gas.gif]] +* Running things from the command line + +It is also possible to evaluate simple code from the command line. For example, +you can play and pause your Spotify app with this: + +#+BEGIN_EXAMPLE +$ gas -e '(js-invoke (Application "Spotify") playpause) +#+END_EXAMPLE + +* Creating a macOS app + +Another sweet thing you can do is create a macOS app: + +#+BEGIN_EXAMPLE +$ gas -a Choices.app examples/choices.gs +#+END_EXAMPLE @@ -34,7 +34,10 @@ exec guile -e "(@@ (gas) main)" -s "$0" "$@" #:use-module (ice-9 textual-ports) #:use-module (language guilescript compile)) -(define (run-osascript js) +(define *guile-logo-icns* "/usr/local/share/gas/guile.icns") +(define *applet-icns* "Contents/Resources/applet.icns") + +(define (create-osascript-file js) (let* ((port (mkstemp "/tmp/gas-XXXXXX")) (tmpfile (port-filename port))) (chmod port #o700) @@ -42,9 +45,21 @@ exec guile -e "(@@ (gas) main)" -s "$0" "$@" port (string-append "#!/usr/bin/osascript -l JavaScript\n\n" js)) (close-port port) + tmpfile)) + +(define (run-osascript js) + (let* ((tmpfile (create-osascript-file js))) (system tmpfile) (delete-file tmpfile))) +(define (create-osascript-app app-name filename) + (let* ((js (compile-file filename)) + (tmpfile (create-osascript-file js))) + (system (format #f "osacompile -l JavaScript -o ~a ~a" app-name tmpfile)) + (when (file-exists? *guile-logo-icns*) + (copy-file *guile-logo-icns* (format #f "~a/~a" app-name *applet-icns*))) + (delete-file tmpfile))) + (define (run-string str) (run-osascript (compile (call-with-input-string str read-syntax)))) @@ -54,6 +69,7 @@ exec guile -e "(@@ (gas) main)" -s "$0" "$@" (define main (match-lambda ((_ "-e" str) (run-string str)) + ((_ "-a" app-name filename) (create-osascript-app app-name filename)) ((_ filename) (run-file filename)) ((_) (display "Usage: gas filename.gs") diff --git a/share/guile.icns b/share/guile.icns Binary files differnew file mode 100644 index 0000000..915eecf --- /dev/null +++ b/share/guile.icns |