Re: saving front window using osascript...
Re: saving front window using osascript...
- Subject: Re: saving front window using osascript...
- From: Fons Rademakers <email@hidden>
- Date: Sat, 10 Nov 2007 02:59:16 +0100
- Keywords: CERN SpamKiller Note: -50 Charset: west-latin
- Keywords: CERN SpamKiller Note: -50 Charset: west-latin
- Organization: CERN
Hi Rick,
thanks for your patient help. I got it to do what I wanted. Here the
solution:
Input: Entire document
Directory: Home
#!/bin/sh
#
# Removes trailing blanks (spaces and tabs) and save to file.
osascript << ENDOFSCRIPT
tell application "Xcode"
set orgText to text of front text document
set text of front text document to do shell script "echo " & quoted
form of orgText & " | perl -pe 's/[\t ]+$//g'"
save the front document
end tell
ENDOFSCRIPT
Output: Discard
Errors: Alert
Cheers, Fons.
Rick Ballard wrote:
On Nov 9, 2007, at 3:16 AM, Fons Rademakers wrote:
#!/bin/sh
#
# Removes trailing blanks (spaces and tabs) from the file.
#
osascript << ENDOFSCRIPT
tell application "Xcode"
set myFile to associated file name of front window
save the front document
do shell script "perl -pe 's/[\t ]+$//g' " & quoted form of myFile &
" > ~/.xc-save.$$; mv ~/.xc-save.$$ " & quoted form of myFile
end tell
ENDOFSCRIPT
but this leaves my editor window empty since no buffer gets written
back in. But as soon as something gets written back in the buffer is
modified, hence not saved. Is there a catch-22 here?
Hi Fons,
I'm not completely sure I understand what you mean. Xcode won't notice
that you've overwritten the file on disk right away, so maybe that's
what you're seeing. Switching applications will trigger a refresh of the
file on disk, as will closing and re-opening it.
You don't need to replace the file on disk in order to modify its
contents, however; you can manipulate the text of the document directly
via applescript. If you browse Xcode's scripting dictionary in script
editor and look at the Text Document class, you should see what you
need. Specificially, you can "set text of front text document to"
whatever you want.
- Rick
--
Org: CERN, European Laboratory for Particle Physics.
Mail: 1211 Geneve 23, Switzerland
E-Mail: email@hidden Phone: +41 22 7679248
WWW: http://fons.rademakers.org Fax: +41 22 7669640
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden