]> gitweb.factorcode.org Git - factor.git/commitdiff
elevate: make it load/compile
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 3 Jul 2018 15:46:13 +0000 (10:46 -0500)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 25 Jan 2022 18:28:28 +0000 (10:28 -0800)
basis/cocoa/apple-script/apple-script-docs.factor
basis/cocoa/apple-script/apple-script.factor
basis/elevate/elevate.factor
basis/elevate/macosx/macosx.factor

index bcecb53248fd69278736fe3737e0529974d341e9..b0872170f2ddd029153459fd01b9adbbc36d41b0 100644 (file)
@@ -3,8 +3,7 @@ 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." } ;
+{ $description "Escape special characters in a string to make it suitable as a literal string in AppleScript code." } ;
 
 HELP: run-apple-script
 { $values { "str" string } }
index 94cff2da82a6dc4eaa59ab0acabf3ecffe10d88c..52d9c6ade91dc31a009d03c0374472e1b3e51974 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2013 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
-USING: cocoa cocoa.application cocoa.classes kernel parser
-multiline words ;
+USING: assocs cocoa cocoa.application cocoa.classes kernel
+multiline parser sequences strings words ;
 IN: cocoa.apple-script
 
 <PRIVATE
@@ -15,10 +15,8 @@ CONSTANT: apple-script-charmap H{
 PRIVATE>
 
 : quote-apple-script ( str -- str' )
-    [
-      1string [ apple-script-charmap at ] [ ] bi or
-    ] { } map-as
-    "" join "\"" dup surround ;
+    [ 1string apple-script-charmap ?at drop ] { } map-as
+    "" concat-as "\"" dup surround ;
 
 : run-apple-script ( str -- )
     [ NSAppleScript -> alloc ] dip
index 820e16996e3a9e0248cc329cd1368d55fc7b88c3..439ed145fdc74e732448d69fcd20c7dbcffe6b24 100644 (file)
@@ -27,6 +27,8 @@ HOOK: lowered  os ( -- )
 
 : elevate ( win-console? posix-graphical? -- ) [ (command-line) t ] 2dip elevated drop ;
 
+os unix? [ "elevate.unix" require ] when
+
 {
     { [ os windows? ] [ "elevate.windows" require ] }
     { [ os linux? ] [ "elevate.linux" require ] }
index 69a0e04abe9a7cf92e1885d7663b3c3af8675c34..d64462fdf2556c5bf90d36688af4afca2ae22763 100644 (file)
@@ -1,20 +1,25 @@
-USING: cocoa.apple-script elevate elevate.unix ;
+USING: accessors arrays cocoa.apple-script elevate
+elevate.unix.private formatting io.launcher kernel locals
+sequences system ;
 IN: elevate.macosx
 
 <PRIVATE
 : apple-script-elevated ( command -- )
-    quote-apple-script
+    first quote-apple-script
     "do shell script %s with administrator privileges without altering line endings"
     sprintf run-apple-script ;
 
 ! TODO
 M:: macosx elevated ( command replace? win-console? posix-graphical? -- process )
-    already-root? [ <process> command >>command 1array ] [
-        posix-graphical? [ ! graphical through applescript
+    already-root? [
+        <process> command >>command 1array
+    ] [
+        ! graphical through applescript
+        posix-graphical? [
             command apple-script-elevated
         ] when
-        posix-elevated
-    ] if ;
+        posix-elevated  "lol3" throw
+    ] if "lol" throw ;
 
 M: macosx lowered
     posix-lowered ;