Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'The long way?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
The long way?
Authored by: gatorparrots on Feb 05, '04 11:43:00AM
This seems like the long way around the problem. We've discussed a different solution in the forum already. The solution basically involves using a heredoc in the shell, so arguments can be fed in as well. Here is Paul McCann's example:
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


[ Reply to This | # ]
The long way?
Authored by: pmccann on Feb 05, '04 06:50:47PM

Here's a much shorter example which might highlight what's going on a little better:

osascript<<END
tell app "Finder" to open ("$1" as POSIX file as alias)
END

Save this as "pmo" (for "poor man's open") or whatever in your ~/bin directory --assuming that /Users/yourusername/bin is in your PATH-- make it executable (chmod u+x ~/bin/pmo), enter "rehash" to get it found and you should be able to do something like

pmo filename.txt

or

pmo ~/bin/pmo

and so forth. (The Finder should use the correct app to open the file.) As promised by the name, it's a pretend "open" command.



[ Reply to This | # ]
The (really!) long way?
Authored by: Krioni on Feb 06, '04 09:45:34AM
Wow. Or you could just use the actual 'open' command. Type

man open
in the Terminal. It opens a file the same way the Finder would, but also lets you 'open' URLs, specify an app, or whatever. No need for "poor man's open" I think.

[ Reply to This | # ]
The (really!) long way?
Authored by: pmccann on Feb 09, '04 06:54:31PM

Oh really? To think that I hadn't noticed. Thanks so much for open-ing my eyes. Now I can go off and recreate some other wheels.

Sheesh...



[ Reply to This | # ]
The long way?
Authored by: jaysoffian on Feb 07, '04 04:12:29PM

The problem with using a HERE document is that osascript has to compile the entire applescript each time. That may be a length operation if you are either running the script multiple times, or it is a long script. Also, you have to emed the entire applescript inside your sh script, which you may not wish to do.

The advantage of this hint, over a here document, is that you can run a pre-compiled script and pass it arguments.



[ Reply to This | # ]
The long way?
Authored by: formido on Feb 10, '04 02:25:20PM

A good point, but if that really becomes a problem, you can just put the main script in a separate, pre-compiled file and only call it from the HERE doc. This allows the complexity of set-up to scale with your needs.



[ Reply to This | # ]