elevate: make it load/compile
parent
281165d7e7
commit
e39a23dc96
|
@ -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 } }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ] }
|
||||
|
|
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue