Pull to refresh

Applescript общего назначения в повседневной офисной работе

Reading time 2 min
Views 11K
Хотелось бы поделиться собственными наработками нескольких решений Applescript, применение для которым может найти буквально каждый, а заодно услышать примеры других похожих универсальных решений «общего назначения». Оговорюсь, что запускаю я скрипты через горячие клавиши, привязав кнопки к запуску нужных скриптов через Quicksilver, эта привязка занимает 5 секунд.

Итак, из таких скриптов общего назначения, которые подойдут буквально каждому вне зависимости деятельности, я создал следующие.
1. Оправить выделенный файл по почте с нужной темой письма, нужным текстом письма и нужному получателю:
property Myrecipient : "ОТПРАВИТЕЛЬ"
property mysubject : "ТЕМА"
property EmailBody : "ТЕКСТ"


on run
	tell application "Finder"
		set sel to (get selection)
	end tell
	new_mail(sel)
end run

on open droppedFiles
	new_mail(droppedFiles)
end open

on new_mail(theFiles)
	tell application "Mail"
		set newMessage to make new outgoing message with properties {visible:true, subject:mysubject, content:EmailBody}
		tell newMessage
			make new to recipient with properties {address:Myrecipient}
			tell content
				repeat with oneFile in theFiles
					make new attachment with properties {file name:oneFile as alias} at after the last paragraph
				end repeat
			end tell
		end tell
		activate
	end tell
end new_mail


2. Открыть нужную папку:
tell application "Finder"
	activate
	open folder "ПАПКА" of folder "НАДПАПКА" of folder "ПОЛЬЗОВАТЕЛЬ" of folder "Users" of startup disk
end tell

3. Сделать напоминание из выделенного письма:
tell application "Mail"
	using terms from application "Mail"
		set selectedMails to selection
		set theMessage to first item of selectedMails
		set theBody to "message:%3C" & message id of theMessage & "%3E"
		set theSubject to the subject of theMessage & " (From " & the sender of theMessage & ")"
		tell application "Reminders"
			set theList to list "Inbox"
			set newToDo to make new reminder with properties {name:theSubject, body:theBody, container:theList}
		end tell
	end using terms from
end tell

4. Покрасить письмо в, к примеру, красный цвет:
tell application "Mail"
	set maillist to selection
	repeat with i from 1 to number of items in maillist
		set this_item to item i of maillist
		if class of this_item is message then
			set background color of this_item to red
			-- other colors are
			-- gray / green / orange / red
		end if
	end repeat
end tell


5. Получить путь к папке или файлу — допустим, для вставки в письмо или чат:
>tell application "Finder"
	set sel to the selection as text
	set the clipboard to POSIX path of sel
end tell

Горячие клавишы на запуск мне показалось удобнее всего делать через Alt — для «пансистемных» обращений она фактически свободна, в то время как на Cmd висит много базовых функций внутри приложений, а на Ctrl — опять-таки многое создается кастомного внутри приложений. А тут alt+r — отправил почту в reminders например.

Был бы очень рад увидеть в комментариях какие-нибудь идеи скриптов, которые могли бы пригодиться для рутинных операций вне зависимости от рода деятельности.
Tags:
Hubs:
+9
Comments 15
Comments Comments 15

Articles