]> gitweb.factorcode.org Git - factor.git/commitdiff
move quote-apple-script to cocoa.apple-script and out of elevate.macosx
authorCat Stevens <catb0t@protonmail.ch>
Fri, 29 Jun 2018 20:46:33 +0000 (16:46 -0400)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 25 Jan 2022 18:28:27 +0000 (10:28 -0800)
basis/cocoa/apple-script/apple-script-docs.factor
basis/cocoa/apple-script/apple-script-tests.factor [new file with mode: 0644]
basis/cocoa/apple-script/apple-script.factor
basis/elevate/macosx/macosx.factor

index 820f08014618dd6bdad0a03ec9bebce53e8efba6..bcecb53248fd69278736fe3737e0529974d341e9 100644 (file)
@@ -1,7 +1,11 @@
 USING: help.markup help.syntax strings ;
-
 IN: cocoa.apple-script
 
+HELP: quote-apple-script 
+{ $values { "str" string } }
+{ $description { "Escape special characters in a string to make it suitable as a literal string in AppleScript code." }
+{ $notes "Because this word is a port from Barney Gale's Elevate.py ("{ $vocab-link elevate }"), the only characters escaped are keys in " { $link apple-script-charmap } "; other special characters are unchanged." } ;
+
 HELP: run-apple-script
 { $values { "str" string } }
 { $description "Runs the provided uncompiled AppleScript code." }
diff --git a/basis/cocoa/apple-script/apple-script-tests.factor b/basis/cocoa/apple-script/apple-script-tests.factor
new file mode 100644 (file)
index 0000000..f5d6d4f
--- /dev/null
@@ -0,0 +1,10 @@
+USING: tools.test ;
+IN: cocoa.apple-script
+
+{ "\\\\" } [ "\\" quote-apple-script ] unit-test
+{ "hello\\nthere" } [ "hello
+there" quote-apple-script ] unit-test ! no space, just a newline
+{ "hello\\rthere" } [ "hello\rthere" quote-apple-script ] unit-test
+{ "hello\\tthere" } [ "hello\tthere" quote-apple-script ] unit-test
+{ "hello\\tthere" } [ "hello   there" quote-apple-script ] unit-test ! actual tab character 0x09
+
index 1507ac9801707e0f5c2bbd74b1507440dcc0bc0f..94cff2da82a6dc4eaa59ab0acabf3ecffe10d88c 100644 (file)
@@ -1,9 +1,24 @@
 ! Copyright (C) 2013 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
+USING: cocoa cocoa.application cocoa.classes kernel parser
+multiline words ;
+IN: cocoa.apple-script
 
-USING: cocoa cocoa.application cocoa.classes kernel parser words ;
+<PRIVATE
+CONSTANT: apple-script-charmap H{
+    { "\n" "\\n" }
+    { "\r" "\\r" }
+    { "\t" "\\t" }
+    { "\"" "\\\"" }
+    { "\\" "\\\\" }
+}
+PRIVATE>
 
-IN: cocoa.apple-script
+: quote-apple-script ( str -- str' )
+    [
+      1string [ apple-script-charmap at ] [ ] bi or
+    ] { } map-as
+    "" join "\"" dup surround ;
 
 : run-apple-script ( str -- )
     [ NSAppleScript -> alloc ] dip
index 81e1cf4a70b1a48537d4c9338db1690955a5571c..69a0e04abe9a7cf92e1885d7663b3c3af8675c34 100644 (file)
@@ -2,18 +2,6 @@ USING: cocoa.apple-script elevate elevate.unix ;
 IN: elevate.macosx
 
 <PRIVATE
-CONSTANT: apple-script-charmap H{
-    { "\n" "\\n" }
-    { "\r" "\\r" }
-    { "\t" "\\t" }
-    { "\"" "\\\"" }
-    { "\\" "\\\\" }
-}
-
-: quote-apple-script ( str -- str' )
-    [ 1string [ apple-script-charmap at ] [ ] bi or ] { } map-as
-    "" join "\"" dup surround ;
-
 : apple-script-elevated ( command -- )
     quote-apple-script
     "do shell script %s with administrator privileges without altering line endings"