Last active
July 22, 2024 15:39
-
-
Save michaelchadwick/c4570eb26262549fec787a1ac10b32ad to your computer and use it in GitHub Desktop.
Extract Notes field from Logic Pro X session file (.logicx)
This file contains hidden or 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
#!/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 { | |
} | |
$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}' \ | |
| awk '{gsub(/\04792/,"\047"); print}' \ | |
) | |
echo "$notes" | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment