on run argv
	if (count of argv) > 0 then
		set sectionTitle to item 1 of argv
		set isRename to item 2 of argv
	else
		error "Section title is not provided" number 60003
	end if
	
	tell application "Microsoft PowerPoint"
		try
			set currentSlide to slide 1 of slide range of selection of active window
		on error errMsg number errNum
			my clickAddSection()
			return "rename new section"
		end try
		
		set currentSection to section number of currentSlide
		set instance to section properties of active presentation
		
		if isRename is "true" then
			rename section instance at position (currentSection + 1) to sectionTitle
		else
			set totalSection to get count of sections of instance
			
			if totalSection = 0 then
				insert section instance before section (currentSection + 1) titled sectionTitle
			else
				insert section instance before section (currentSection + 2) titled sectionTitle
			end if
		end if
	end tell
end run

to clickAddSection()
	tell application "System Events"
		tell process "Microsoft PowerPoint"
			click menu item 5 of menu 6 of menu bar 1
		end tell
	end tell
end clickAddSection