Re: Mac vs unix Carriage returns on a text file format
Re: Mac vs unix Carriage returns on a text file format
- Subject: Re: Mac vs unix Carriage returns on a text file format
- From: Dennis Jones <email@hidden>
- Date: Thu, 31 Mar 2005 14:56:09 -0800
I had a similar problem with files I downloaded from an IBM mainframe
which came in with DOS type line ends.
Two things seemed to solve the problem.
1) I wrote a script based on the Finder Script "Add to names" provided
by apple where I added .txt to the end of each file.
2) The same script I called a small app "LineBreak" which changes the
line breaks between Mac, Unix & DOS.
See snipits of my code below
Dennis
email@hidden
-- code --
-- Get current folder name -- "sourceFolder"
try
tell application "Finder" to set the sourceFolder to (folder of the
front window) as alias
on error -- no open folder windows
set the sourceFolder to path to desktop folder as alias
end try
set the thePrefix to ""
repeat
display dialog "Enter the date (YYMMDD)" default answer the thePrefix
buttons {"Cancel", "OK"} default button 2
copy the result as list to {the thePrefix, the button_pressed}
set the thePrefix to the thePrefix & "-"
if the thePrefix is not "" then exit repeat
end repeat
---------- Main -------------
prefix_suffix(thePrefix, "prefix", sourceFolder) -- adds a prefix to
each file in a folder
prefix_suffix(".txt", "suffix", sourceFolder) -- adds .txt to each
file in a folder
strip_spaces(sourceFolder) -- stripps all spaces from file names in a folder
Run_LineBreak(sourceFolder) -- changes all line breaks to Mac (set
LineBreak prefs to Mac)
-- other code --
---------- Sub Routines -------------
on prefix_suffix(theString, button_pressed, sourceFolder)
set the thePrefix to theString
set the item_list to list folder sourceFolder without invisibles
set sourceFolder to sourceFolder as string
repeat with i from 1 to number of items in the item_list
set this_item to item i of the item_list
set this_item to (sourceFolder & this_item) as alias
set this_info to info for this_item
set the current_name to the name of this_info
if folder of this_info is false and ¬
alias of this_info is false then
if the button_pressed is "Prefix" then
set the new_file_name to the (the thePrefix & the current_name) as string
else
set the new_file_name to the (the current_name & the thePrefix) as string
end if
my set_item_name(this_item, the new_file_name)
end if
end repeat
beep 2
end prefix_suffix
on strip_spaces(sourceFolder)
set the search_parameter to "File Names"
set the search_string to " "
set the replacement_string to ""
set the item_list to list folder sourceFolder without invisibles
set sourceFolder to sourceFolder as string
repeat with i from 1 to number of items in the item_list
set this_item to item i of the item_list
set this_item to (sourceFolder & this_item) as alias
set this_info to info for this_item
set the current_name to the name of this_info
set change_flag to false
if the current_name contains the search_string then
if the search_parameter is "Folder Names" and ¬
folder of this_info is true then
set the change_flag to true
else if the search_parameter is "File Names" and ¬
folder of this_info is false then
set the change_flag to true
else if the search_parameter is "Both" then
set the change_flag to true
end if
if the change_flag is true then
-- replace target string using delimiters
set AppleScript's text item delimiters to the search_string
set the text_item_list to every text item of the current_name
set AppleScript's text item delimiters to the replacement_string
set the new_item_name to the text_item_list as string
set AppleScript's text item delimiters to ""
my set_item_name(this_item, new_item_name)
end if
end if
end repeat
end strip_spaces
on Run_LineBreak(sourceFolder)
tell application "TextEdit"
activate
--set miniatruized of window 1 to true
open sourceFolder
delay 1
ignoring application responses
quit
end ignoring
end tell
end Run_LineBreak
On Thu, 31 Mar 2005 13:08:53 -0500, Dan Doughtie
<email@hidden> wrote:
> I ported over a script from OS 9 to OS X and had to do some major
> renovations because the original used Dialog Director.
>
> Essentially the script grabbed data and put it into a fixed file format
> that an interface inserted the data into a Sybase database.
>
> Here's where the challenge is. The carriage returns are not being read by
> the interface properly. I've forced all returns to Ascii 10 and ascii 13. No
> luck. I can open the file in BBEdit and looks perfect. If I tell Bbedit to
> save the file with Mac Carriage Returns then it works perfect.
> Without that then it has problems parsing the data.
>
> Is there any syntax to save a text file through the Finder and tell it to
> save it as Mac linefeeds? Or will I have to open it in a scriptable app and
> let the app do it?
>
> Dan
> --
>
> Dan Doughtie
> Business Analyst
> Morris Technology Services
> 706-823-3464
> AIM: MTSDanD
>
> Nothing contained in this e-mail is intended to be an offer to commit
> Morris Communications Company to any purchase, sale, contract or other
> course of action.
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Applescript-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
>
--
Dennis Jones
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden