Copy Description to Clipboard as Plain Text Plus Add Contents of Text File Example

This AppleScript is designed to read the contents of a text file I created and saved within new subfolders I created within a existing GarageSale related parent folder.

The folder contains text I want to tack onto the end of each item I post of Facebook Marketplace.

The AppleScript, saved an an app, converts the description to plain text and adds the content of this file to the end so I can then past it in Facebook Marketplace’s listing form.

DriveName > Users:UserName > Library:Containers:com.iwascoding > garagesale9:Data:Library > Application Support > GarageSale > Facebook > Terms > NoShipping.txt

Replace “DriveName” with name of hard drive that file is stored.

Replace “UserName” with the Macintosh’s user name.

Replace “NoShipping.txt” to whatever the text file is named on your computer.

The above path to the file will depend on where its stored on your computer - this is a example only.

Change “GarageSale 9.8.1” to whatever GS is named on your computer.

The particular template I use in GS will cause a blank line to appear above the text description after its been converted from HTML to plain text so the following code removes that blank line before copying the description to the clipboard. You can remove these lines of code if that does not apply to your template.

if length of first paragraph of plain_text is 0 then
	set AppleScript's text item delimiters to return
	set AllParagraphs to paragraphs of plain_text
	set FirstParagraphRemoved to items 2 thru -1 of AllParagraphs
	set FirstParagraphRemovedString to FirstParagraphRemoved as string
end if
set TermsFileName to "DriveName:Users:UserName:Library:Containers:com.iwascoding.garagesale9:Data:Library:Application Support:GarageSale:Facebook:Terms:NoShipping.txt" as alias

set TermsText to read TermsFileName

tell application "GarageSale 9.8.1"
	repeat with theListing in (get selected ebay listings)
		set des to get the description of theListing
	end repeat
end tell

set theText to des

set plain_text to do shell script "echo " & quoted form of ("<!DOCTYPE HTML PUBLIC><meta charset=\"UTF-8\">" & theText) & space & "| textutil -convert txt -stdin -stdout"

if length of first paragraph of plain_text is 0 then
	set AppleScript's text item delimiters to return
	set AllParagraphs to paragraphs of plain_text
	set FirstParagraphRemoved to items 2 thru -1 of AllParagraphs
	set FirstParagraphRemovedString to FirstParagraphRemoved as string
end if

set the clipboard to FirstParagraphRemovedString & TermsText