Skip to content

Instantly share code, notes, and snippets.

@michaelchadwick
Last active November 13, 2023 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelchadwick/c4570eb26262549fec787a1ac10b32ad to your computer and use it in GitHub Desktop.
Save michaelchadwick/c4570eb26262549fec787a1ac10b32ad to your computer and use it in GitHub Desktop.
Extract Notes field from Logic Pro X session file (.logicx)
#!/usr/bin/env bash
## get the Notes field from a Logic Pro X project (e.g. lyrics)
function lpxnotes_dump() {
# Check if a filename is provided as an argument
if [ "$#" -ne 1 ]; then
echo "Usage: lpxnotes_dump <filename>"
else
# assuming only one Alternative
filename=$1/Alternatives/000/ProjectData
# Check if the file exists
if [ ! -e "$filename" ]; then
echo "File not found: $filename"
else
# regex pattern for code where Notes start and end (in LPX 10.7, at least)
pattern='\\\\f0\\\\fs30'
end_pattern='}'
# find first, and only first, instance of this to capture Project Notes
str=$(strings "$filename" | awk -v pattern="$pattern" -v end_pattern="$end_pattern" '
$0 ~ pattern {
flag=1
}
flag {
print
}
$0 ~ end_pattern && flag {
flag=0
exit
}
')
# clean up output
notes=$(
echo "$str" \
| awk '{gsub(/pard.+/,""); print}' \
| awk '{gsub(/\\f0\\fs30/,""); print}' \
| awk '{gsub(/\\cf2 /,""); print}' \
| awk '{gsub(/^ /,""); print}' \
| awk '{gsub(/\\/,""); print}' \
| awk '{gsub(/\}/,""); print}' \
| awk '{gsub(/^[\s]+$/,""); print}' \
| awk '{gsub(/qSxT/,""); print}'
)
echo "$notes"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment