Action

Bocciaman AS Date List

Posted by sylumer, Last update 11 months ago - Unlisted

Steps

  • runAppleScript

    on execute()
    	set theCurrentDate to (current date)
    	set theWeekday to weekday of theCurrentDate
    	
    	if theWeekday = Monday then
    		set startingDate to theCurrentDate
    	else if theWeekday = Tuesday then
    		set startingDate to theCurrentDate - 1 * days
    	else if theWeekday = Wednesday then
    		set startingDate to theCurrentDate - 2 * days
    	else if theWeekday = Thursday then
    		set startingDate to theCurrentDate - 3 * days
    	else if theWeekday = Friday then
    		set startingDate to theCurrentDate - 4 * days
    	else if theWeekday = Saturday then
    		set startingDate to theCurrentDate - 5 * days
    	else if theWeekday = Sunday then
    		set startingDate to theCurrentDate - 6 * days
    	else
    		error number -128
    	end if
    	
    	set dateList to {date string of startingDate}
    	repeat with i from 1 to 4
    		set theDate to startingDate + i * days
    		set end of dateList to date string of theDate
    	end repeat
    	
    	dateList --> {"Monday, September 6, 2021", "Tuesday, September 7, 2021", "Wednesday, September 8, 2021", "Thursday, September 9, 2021", "Friday, September 10, 2021"}
    	
    	set {TID, text item delimiters} to {text item delimiters, linefeed}
    	set dateList to dateList as text
    	set text item delimiters to TID
    	
    	return dateList -- a string of paragraphs of the dates
    end execute
  • script

    // Insert the AppleScript result.
    editor.setSelectedText(context.appleScriptResponses.join("\n"));
    
    // For convenience let's move the cursor to the end of the inserted text and activate the editor.
    editor.setSelectedRange(editor.getSelectedRange()[0] + editor.getSelectedRange()[1], 0);
    editor.activate();

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.