Last active
August 29, 2015 14:12
-
-
Save dougtoppin/b35ef79df3c147871a45 to your computer and use it in GitHub Desktop.
example of using AppleScript to read a text file with 4 tab delimited fields in it and echo the fields in each line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
example of using AppleScript to read a text file with 4 tab delimited fields in it and echo the fields in each line | |
example input lines (tabs between each field except blank between date and time): | |
1 field2 field3 2013-10-25 20:57:48 | |
2 field2 field3 2013-11-18 02:53:34 | |
Output should look something like: | |
(*item number: 1*) | |
(* tag: field2*) | |
(* item text: field3*) | |
(* item timestamp: 2013-10-25 20:57:48*) | |
(*item number: 2*) | |
(* tag: field2*) | |
(* item text: field3*) | |
(* item timestamp: 2013-11-18 02:53:34*) | |
*) | |
set myfile to "notes.txt" -- input file | |
set tid to AppleScript's text item delimiters -- preserve initial text delimiters | |
set allRecords to read myfile using delimiter linefeed -- read file | |
repeat with aRecord in allRecords -- iterate on each line read from file | |
if length of aRecord is greater than 0 then -- ignore null lines | |
set text item delimiters to tab -- prepare to parse line using tab | |
set theTextItems to text items of aRecord -- parse line into fields | |
set AppleScript's text item delimiters to tid -- restore text delimiters | |
log "item number: " & item 1 of theTextItems | |
log " tag: " & item 2 of theTextItems | |
log " item text: " & item 3 of theTextItems | |
log " item timestamp: " & item 4 of theTextItems | |
end if | |
end repeat |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a large number of lines of text in a file that I want to import into Evernote as individual notes.
This script is the start of using AppleScript to read and parse the file.
Next will come how to send it to Evernote.