On 2007-11-20, at 07:10, Fons Rademakers wrote:
#!/bin/sh
# Removes trailing blanks (spaces and tabs) and save to file.
osascript << ENDOFSCRIPT
tell application "Xcode"
set myFile to associated file name of front window
set textDocuments to text documents
repeat with i in textDocuments
if path of i is myFile then
set orgText to text of i
set text of i to do shell script "echo " & quoted form of orgText & " | tr '\r' '\n' | perl -pe 's/[\t ]+$//g'"
save i
end if
end repeat
end tell
ENDOFSCRIPT
Hey Fons,
Here's a different approach to your situation. I think you might be able to adapt. There are a few factors involved that could subvert the process. One is that I have my Xcode preferences set to save always. Another is that there could possibly be some issues with Spotlight hanging on to altered files -- this was a known problem in 10.4 and I don't know if it's been addressed in 10.5. One way to work around it is to tell the Finder to 'update' the files after they've been closed/changed and maybe insert a 'delay' afterwards in the script. Here I get every file in target 1. You can branch on the file type or the subset which would be the paths of the current text documents.
tell application "Xcode"
close (every text document) saving yes
set flist to {}
tell active project document
tell target 1
set flist to real path of file reference of every build file
end tell
end tell
-- do perl stuff, update, delay
open flist
end tell
Philip Aker