|
|
#1 |
|
Triple-A Player
Join Date: Dec 2003
Location: Tokyo, Japan
Posts: 76
|
Hi,
in the osascript man pages it says that multiple -e command can be put together in one command line. -e command Enter one line of a script. If -e is given, osascript will not look for a filename in the argument list. Multiple -ecommands may be given to build up a multi-line script. Because most scripts use characters that are special to many shell programs (e.g., AppleScript uses single and double quote marks, ``('', ``)'', and ``*''), the command will have to be correctly quoted and escaped to get it past the shell intact. I assume that the multiple -e command can be used to execute a small applescript in one command line without having calling an applescript with osascript. The question I have is: How does the code for a multiple -e command look like? As an example I would like to execute the following applescript at the command line: tell application "Finder" delete file "Untitled.rtf" end tell Detlef |
|
|
|
|
|
#2 |
|
Major Leaguer
Join Date: Aug 2003
Posts: 429
|
You example is actually one command which could be expressed as:
Code:
tell application "Finder" to delete file "Untitled.rtf" Code:
osascript -e 'tell application "Finder" to delete file "untitled.rtf"' Code:
tell application "Finder" delete file "Untitled.rtf" delete file "untitled2.rtf" end tell Code:
osascript -e 'tell application "Finder" to delete file "untitled.rtf"' -e 'tell application "Finder" to delete file "untitled2.rtf"' -- Rob |
|
|
|
|
|
#3 |
|
Triple-A Player
Join Date: Dec 2003
Location: Tokyo, Japan
Posts: 76
|
good explanation. Thank you very much.
Detlef |
|
|
|
|
|
#4 |
|
Major Leaguer
Join Date: Jan 2002
Location: Adelaide, South Australia
Posts: 470
|
The "multiple -e" method of using longer applescripts works OK, but it's also worth knowing the "HEREDOC" method, which allows you to cut and paste applescript snippets into shell scripts and have them executed by osascript. An example should do the trick... here's a command that makes a new terminal window offset from the frontmost such thing. (10.3's terminal now behaves perfectly, so the script's pretty much useless: but it illustrates the technique). I called it "nt", and threw it in my ~/bin directory. You call it using something like "nt 'cd junk'", or just a raw "nt".
Code:
osascript<<END
set init to {40, 40} --top left corner of window relative to top left of screen
set dx to 20 --amount to shift each new window right
set dy to 30 --amount to shift each new window down
tell application "Terminal"
set thewindows to (every window)
set num to the length of thewindows
do script "$1"
set tl to {(item 1 of init)+dx*num,(item 2 of init)+dy*num}
set position of window 1 to tl
activate
end tell
END
Cheers, Paul |
|
|
|
|
|
#5 |
|
Triple-A Player
Join Date: Dec 2003
Location: Tokyo, Japan
Posts: 76
|
pmccann,
thanks for the hint. I finally got a chance to try it out with some of my applescripts. It works great. Detlef |
|
|
|
![]() |
|
|