I am working on a script that is capable of saving a guitar tab from a url into a pdf in iCloud. I am able to get the tab itself as a string but it contains line breaks ( “\n” ) that do not occur when saving the string into a file.
Anyone got to deal with these type of issue before?
Here’s my code:
let url = "https://tabs.ultimate-guitar.com/tab/metallica/and_justice_for_all_tabs_202703"
let req = new Request(url)
let html = await req.loadString()
let tabStart = html.indexOf('{"wiki_tab":{"content":"')
let tabEnd = html.indexOf('","revision_id":',tabStart+1)
let tab = html.substring(tabStart+24,tabEnd)
const fileManager = FileManager.iCloud()
const outputPath = fileManager.joinPath(fileManager.documentsDirectory(),'/tab.txt')
fileManager.writeString(outputPath, tab)
I’m confused as to what the issue is. Are you saying it doesn’t save because of the line break, or what exactly is happening and what do you want to happen?
incidentally, have you tried to do a .replace() on the string to remove the line break?
Right now, I’m not sure if this is a bug caused by Request.loadString() or if there’s something fishy with the content on Ultimately Guitar. I’ll take a look at that.
Okay, so Ultimate Guitar has a string in a JSON object that contains the “\n” string and we want to replace that with an actual line break. Therfore I don’t think this is a bug in Scriptable nor Ultimate Guitar. This is the expected behaviour.