summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Conchillo FlaquƩ <aconchillo@gmail.com>2022-02-04 21:43:29 -0800
committerAleix Conchillo FlaquƩ <aconchillo@gmail.com>2022-02-04 21:43:29 -0800
commitdc01c64370a8ab2dab83bb4a024feeb1727a0491 (patch)
treeecadc89dbc71d76c996d38796db620cc36828011
parentba5e1879b584bcbc21e7cb277aae0fea0c14fe0d (diff)
allow creating application bundles
-rw-r--r--Makefile2
-rw-r--r--README.org21
-rwxr-xr-xgas18
-rw-r--r--share/guile.icnsbin0 -> 26745 bytes
4 files changed, 38 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 32beb0b..ab11db9 100644
--- a/Makefile
+++ b/Makefile
@@ -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'
diff --git a/README.org b/README.org
index cefdc59..ee5f971 100644
--- a/README.org
+++ b/README.org
@@ -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
diff --git a/gas b/gas
index ac5c2dc..2d643fe 100755
--- a/gas
+++ b/gas
@@ -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
new file mode 100644
index 0000000..915eecf
--- /dev/null
+++ b/share/guile.icns
Binary files differ