Help with code - formatting icalbuddy output

I have this calendar code pulling event info from a specific calendar. I would like to change the output to 2 lines (Currently this will output all event info on a single line). Ive tried a few ways of doing this, they have all failed. Would like the last part of this code ":arrow_forward:︎" substr($4,19)}'"" displayed on the second line.

set upcomingEvents to do shell script "/usr/local/bin/icalBuddy -ic \"Schedule\" -n -nc -ps \"|• |\" -iep \"title,datetime,location\" -po \"datetime,title,location\" -tf \"%1I:%M %p\" -df \"%b %d\" -ea -eed eventsToday+10 | head -n 1 | awk -F \"• \" '{print toupper(substr($2,1,1)) tolower(substr($2,2))\" -\" substr($3,4)\" ▶︎\" substr($4,19)}'"

I do this to, I ended up running two commands. One for the info in the first line, one to the info for the second line.

-- start time here

set upcomingEventsTime to do shell script "/usr/local/bin/icalBuddy -n -nc -ic D67AE76B-5C14-4966-8F2A-716825956339 -ec -ps \"|• |\" -iep \"datetime\" -po \"datetime\" -tf \"%1Hh%M\" -df \"%a\" -eed eventsToday+7 | awk -F \"• \" '{print toupper(substr($2,1,1)) tolower(substr($2,2))\"\"$3}'"

set eventsListTime to theSplit(upcomingEventsTime, "

")

set findReplaceTime to the first item of eventsListTime

--Delete 'Today at'

set outputTime to replaceText("Today at ", "", findReplaceTime)

-- start title here

set upcomingEventsTitle to do shell script "/usr/local/bin/icalBuddy -n -nc -ic D67AE76B-5C14-4966-8F2A-716825956339 -ec -ps \"|• |\" -iep \"title\" -po \"title\" -tf \"%1Hh%M\" -df \"%a\" -eed eventsToday+7 | awk -F \"• \" '{print toupper(substr($2,1,1)) tolower(substr($2,2))\"\"$3}'"

set eventsListTitle to theSplit(upcomingEventsTitle, "

")

set findReplaceTitle to the first item of eventsListTitle

--Delete 'Today at'

set outputTitle to replaceText("Today at ", "", findReplaceTitle)

--return bith here

return outputTime & "

" & outputTitle

on theSplit(theString, theDelimiter)

-- save delimiters to restore old settings

set oldDelimiters to AppleScript's text item delimiters

-- set delimiters to delimiter to be used

set AppleScript's text item delimiters to theDelimiter

-- create the array

set theArray to every text item of theString

-- restore the old setting

set AppleScript's text item delimiters to oldDelimiters

-- return the result

return theArray

end theSplit

--@yyuuiko: Find Replace function

on replaceText(find, replace, subject)

--set subject to "a"

set prevTIDs to text item delimiters of AppleScript

set text item delimiters of AppleScript to find

set subject to text items of subject

set text item delimiters of AppleScript to replace

set subject to subject as text

set text item delimiters of AppleScript to prevTIDs

return subject

end replaceText

--thanks @yyuuiko for the base of the code

Thanks, I may have to go that route. Seems I should be able to pass a carriage return, but doesn't work. :frowning:

mh that should work with "\n" in the returned string. But escaping this stuff im shell scripts run from apple scripts can be nasty. I'll look into it tomorrow.

Thats what I thought too. Tried and failed \r \n, no good... Would be much cleaner code then calling icalbuddy twice. Quickly edited my code and have the output working calling it twice (wasn't difficult), but its just ugly IMO. Actually all of icalbuddy is pretty ugly code. LOL

1 Like

I did a little work with two calls to icalbuddy. As much as I dont like that, I do have some output I can work with. Still needs some work and I'm going to clean up some of this code for my use. Using this to re-format my sports schedules.

How come this is being run from an AppleScript ? It would make more sense to run it from a shell script, or does BTT not give that option ?

This would be pure gold, worth for speed and energy!
Unfortunately I didn't manage getting two lines, and more important how to select one item from the string :confused: