• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: saving front window using osascript...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: saving front window using osascript...


  • Subject: Re: saving front window using osascript...
  • From: Philip Aker <email@hidden>
  • Date: Wed, 21 Nov 2007 13:28:22 -0800

On 2007-11-21, at 06:17, Fons Rademakers wrote:

my problem is with what osascript is doing with the text when setting it to a text document. It breaks lines at "\n", not the byte value \n. I tried also to change the Applescript's text separation char to 10 or 13 but that did not help here.

I think one of the key items is the

[altering line endings boolean] : change all line endings to Mac-style and trim a trailing one (default true)

parameter to do shell script.

You should double check the body of your script in Script Editor. The following is what SE can handle but I don't know if it's going to attain your desired result.

do shell script "echo " & quoted form of orig & " | tr \"\\r\" \"\\n\"" without altering line endings
result contains (ASCII character 13)
--> false

I was vaguely suggesting to deal with the files on disk with a perl script on disk so as to avoid the above…

Philip


Philip Aker wrote:
On 2007-11-20, at 07:10, Fons Rademakers wrote:
#!/bin/sh
# Removes trailing blanks (spaces and tabs) and save to file.
osascript &lt;&lt; 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
echo email@hidden <mailto:email@hidden>@nl | tr a-z@. p-za-o.@

Philip Aker
echo email@hidden@nl | tr a-z@. p-za-o.@

 _______________________________________________
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

References: 
 >saving front window using osascript... (From: Fons Rademakers <email@hidden>)
 >Re: saving front window using osascript... (From: Rick Ballard <email@hidden>)
 >Re: saving front window using osascript... (From: Fons Rademakers <email@hidden>)
 >Re: saving front window using osascript... (From: Rick Ballard <email@hidden>)
 >Re: saving front window using osascript... (From: Fons Rademakers <email@hidden>)
 >Re: saving front window using osascript... (From: Rick Ballard <email@hidden>)
 >Re: saving front window using osascript... (From: Fons Rademakers <email@hidden>)
 >Re: saving front window using osascript... (From: Philip Aker <email@hidden>)
 >Re: saving front window using osascript... (From: Fons Rademakers <email@hidden>)

  • Prev by Date: Re: Problem loading IB plugin [solved]
  • Next by Date: Re: Problem loading IB plugin [solved]
  • Previous by thread: Re: saving front window using osascript...
  • Next by thread: having trouble debugging a linker error
  • Index(es):
    • Date
    • Thread