• 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
Unwanted null characters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unwanted null characters


  • Subject: Unwanted null characters
  • From: Joe <email@hidden>
  • Date: Thu, 4 Oct 2007 11:22:05 -0700


Recently, Michelle posted a fragment for getting Safari's selected text. Based on that, I wrote a script to put Safari's selected text into a text file for further use. Unfortunately, while the output looks fine, there appears to be a null character between every character in the file written by the script.


<MY SCRIPT>

tell application "Safari"
set selectedText to do JavaScript "unescape(getSelection())" in document 1
set theurl to get URL of document 1
end tell
set currentDate to (current date) as text
set clipFile to (path to desktop folder as text) & "SafariText.txt"
try
close access file clipFile
end try
set myFileRef to open for access file clipFile with write permission
write (currentDate & return & theurl & return & "-------------------" & return & selectedText & return & "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & ¬
return & return) to myFileRef starting at eof
close access myFileRef


<END>

I accidentally discovered the presence of the nulls when I tried pasting a URL from the text file into a browser - It failed.

I can open the file, select a bit of text and drag it onto the desktop as a clipping file. The file name of the clipping reveals part of the problem.

Example clipping name:
h-t-t-p---/-/-w-w-w-.-b-o-s- 1

The original text (and I don't know if this will send correctly) was this:
http://www.boston.com/news/globe/


But while that shows up with spaces between each character here in Mail, it does not when viewed in TextEdit (where it looks correct).

My question is how can I remove null characters with AppleScript before writing to file?

Thanks
Joe


_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: Unwanted null characters
      • From: Doug McNutt <email@hidden>
  • Prev by Date: Re: CS3 Change text properties
  • Next by Date: Re: Unwanted null characters
  • Previous by thread: Re: AppleScript-Users Digest, Vol 4, Issue 479
  • Next by thread: Re: Unwanted null characters
  • Index(es):
    • Date
    • Thread