move quote-apple-script to cocoa.apple-script and out of elevate.macosx
parent
628d75e410
commit
281165d7e7
|
@ -1,7 +1,11 @@
|
||||||
USING: help.markup help.syntax strings ;
|
USING: help.markup help.syntax strings ;
|
||||||
|
|
||||||
IN: cocoa.apple-script
|
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
|
HELP: run-apple-script
|
||||||
{ $values { "str" string } }
|
{ $values { "str" string } }
|
||||||
{ $description "Runs the provided uncompiled AppleScript code." }
|
{ $description "Runs the provided uncompiled AppleScript code." }
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -1,11 +1,25 @@
|
||||||
! Copyright (C) 2013 John Benediktsson
|
! Copyright (C) 2013 John Benediktsson
|
||||||
! See http://factorcode.org/license.txt for BSD license
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
USING: cocoa cocoa.application cocoa.classes kernel parser
|
USING: cocoa cocoa.application cocoa.classes kernel parser
|
||||||
multiline words ;
|
multiline words ;
|
||||||
|
|
||||||
IN: cocoa.apple-script
|
IN: cocoa.apple-script
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
CONSTANT: apple-script-charmap H{
|
||||||
|
{ "\n" "\\n" }
|
||||||
|
{ "\r" "\\r" }
|
||||||
|
{ "\t" "\\t" }
|
||||||
|
{ "\"" "\\\"" }
|
||||||
|
{ "\\" "\\\\" }
|
||||||
|
}
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
|
: quote-apple-script ( str -- str' )
|
||||||
|
[
|
||||||
|
1string [ apple-script-charmap at ] [ ] bi or
|
||||||
|
] { } map-as
|
||||||
|
"" join "\"" dup surround ;
|
||||||
|
|
||||||
: run-apple-script ( str -- )
|
: run-apple-script ( str -- )
|
||||||
[ NSAppleScript -> alloc ] dip
|
[ NSAppleScript -> alloc ] dip
|
||||||
<NSString> -> initWithSource: -> autorelease
|
<NSString> -> initWithSource: -> autorelease
|
||||||
|
|
|
@ -2,18 +2,6 @@ USING: cocoa.apple-script elevate elevate.unix ;
|
||||||
IN: elevate.macosx
|
IN: elevate.macosx
|
||||||
|
|
||||||
<PRIVATE
|
<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 -- )
|
: apple-script-elevated ( command -- )
|
||||||
quote-apple-script
|
quote-apple-script
|
||||||
"do shell script %s with administrator privileges without altering line endings"
|
"do shell script %s with administrator privileges without altering line endings"
|
||||||
|
|
Loading…
Reference in New Issue