Skip to content

Instantly share code, notes, and snippets.

@shaoshing
Last active December 11, 2015 17:29
Show Gist options
  • Save shaoshing/4635020 to your computer and use it in GitHub Desktop.
Save shaoshing/4635020 to your computer and use it in GitHub Desktop.
Shell script to convert Numbers file to txt that could imported to Flashcard Deluxe (an iOS app)
#!/bin/bash
#
# Usage:
# convert.sh ~/Downloads/Cards.numbers
# (must specify full path)
#
# AppleScript to convert from numbers to csv
osascript -e '
on run argv
set number_file to item 1 of argv
set csv_path to (text 1 thru -8 of number_file) & "csv" -- replace name extension
tell application "Numbers"
open number_file
save document 1 as "LSDocumentTypeCSV" in csv_path
close every window saving no
end tell
end run
' "$1"
CSV=`echo $1 | sed "s/numbers/csv/"`
TXT=`echo $1 | sed "s/numbers/txt/"`
ruby -e '
require "csv"
File.write(ARGV[1], CSV.open(ARGV[0]).map do |line|
(line[0]+"\t"+line[1]).gsub("\n","|")
end.join("\n"))
' "$CSV" "$TXT"
rm "$CSV"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment