用户工具

站点工具


侧边栏

Navigation

applescript

AppleScript

AppleScript 是 Mac OS 系统提供的一种脚本语言,利用该语言我们可以给系统和提供该脚本接口的 app 编写一些小操作,来提高效率,减少重复、复杂的操作。

支持 AppleScript 的 App

Address Book

将 Mac 通讯录里的电话发布 Omnifocus 任务

保留原作者信息,仅仅修改了脚本存放目录'~/Library/Application Scripts/com.apple.AddressBook/'
Contacts to Phone Follow Up with OmniFocus.scpt
--==============================
-- Contacts > Phone Call Follow Up with OmniFocus
-- Version 1.0.0
-- Written By: Ben Waldie <ben@automatedworkflows.com>
-- http://www.automatedworkflows.com
 
-- Description: This script is a Contacts app plug-in, which adds a "Follow Up with OmniFocus" rollover to contact phone number fields. When selected, it creates an OmniFocus followup task."
 
-- Installation: Save as a compiled script into ~/Library/Application Scripts/com.apple.AddressBook/
 
-- Usage: Select "Follow Up with OmniFocus" from the phone number popup on a contact in the Contacts app.
 
-- Version History:
-- 1.0.0 - Initial release
--==============================
 
-- "using terms from" is necessary to let AppleScript know that these event handlers are terminology that belongs to the Contacts app.
using terms from application "Contacts"
 
	-- This handler returns the Contacts property for which the plug-in should function.
	on action property
		return "phone"
	end action property
 
	-- This handler returns the name of the plug-in to be displayed in the Contacts property popup menu.
	on action title
		return "Follow Up with OmniFocus"
	end action title
 
	-- This handler basically tells the Contacts app that this plug-in should be enabled for a given person.
	on should enable action with theProperty for thePerson
		if theProperty is not equal to missing value then
			return true
		else
			return false
		end if
	end should enable action
 
	-- This handler runs when the plug-in is selected from the Contacts property popup menu.
	on perform action with theProperty for thePerson
 
		-- Target the contact from where the plug-in was triggered
		tell application "Contacts"
			tell thePerson
 
				-- Determine whether the contact is a company, and if so, retrieve their company name.
				if company = true then
					set theName to organization
 
					-- If the company name is not populated, then retrieve their name.
					if theName = missing value then set theName to name
 
					-- If the contact is not a company then retrieve their name.
				else
					set theName to name
				end if
			end tell
 
			-- Retrieve the value of the property that triggered the plug-in.  This should be the contact's phone number.
			set thePhoneNumber to value of theProperty
		end tell
 
		-- Target OmniFocus' quick entry window
		tell application "OmniFocus"
			tell quick entry
 
				-- Create a new followup task and note.
				make new inbox task with properties {name:"Phone Call Followup with " & theName, note:"Phone Number: " & thePhoneNumber}
 
				-- Expand the task to display the note.
				set note expanded of every tree to true
 
				-- Open the task
				open
			end tell
		end tell
	end perform action
end using terms from

Word

微软为 Mac OS 平台开发的 Office 套件提供了丰富的 AS 接口,彰显大厂水准。以下提供一个简单的脚本。

引导式替换关键词

工作原因有个制式文档,每个重复任务的流程收尾都是编辑这个文档,所以我设定了很多替换关键词,每次替换这些关键词就行,但是每次编辑的时候都记不住都有哪些关键词,就想能否有个列表或是类似的功能,将特定关键词分别替换了多好。AppleScript能解决✌️。

该脚本的用法是打开需要替换的 word 文档,全选文字后运行该脚本即可
ReplaceKeyWords.scpt
property keyWords : {"案号", "原审", "事由", "卷宗数", "领导", "日期", "wenshu", "案由"}
 
tell application "Microsoft Word"
	set findRange to find object of selection
	tell findRange
		repeat with displayText in keyWords
			(*log displayText
			set replaceText to text returned of (display dialog displayText default answer displayText)
			execute find find text displayText replace with replaceText replace replace all*)
			if text of displayText is equal to "案号" then
				log displayText
				set replaceText to text returned of (display dialog displayText & ":" & "(201x)xxxxx号" default answer displayText)
				execute find find text displayText replace with replaceText replace replace all
			else
				if text of displayText is equal to "原审" then
					log displayText
					set replaceText to text returned of (display dialog displayText & ":" & "xx县、xx区" default answer displayText)
					execute find find text displayText replace with replaceText replace replace all
				else
					if text of displayText is equal to "事由" then
						set replaceText to text returned of (display dialog displayText & ":" & "xxx因xx纠纷" default answer displayText)
						execute find find text displayText replace with replaceText replace replace all
					else
						if text of displayText is equal to "卷宗数" then
							set replaceText to text returned of (display dialog displayText & ":" & "壹、贰。。。" default answer displayText)
							execute find find text displayText replace with replaceText replace replace all
						else
							if text of displayText is equal to "领导" then
								set replaceText to text returned of (display dialog displayText & ":" & "签发人" default answer displayText)
								execute find find text displayText replace with replaceText replace replace all
							else
								if text of displayText is equal to "日期" then
									set replaceText to text returned of (display dialog displayText & ":" & "退卷日期" default answer displayText)
									execute find find text displayText replace with replaceText replace replace all
								else
									if text of displayText is equal to "wenshu" then
										set replaceText to text returned of (display dialog displayText & ":" & "民事裁定、民事判决" default answer displayText)
										execute find find text displayText replace with replaceText replace replace all
									else
										if text of displayText is equal to "案由" then
											set replaceText to text returned of (display dialog displayText & ":" & "xx纠纷" default answer displayText)
											execute find find text displayText replace with replaceText replace replace all
										end if
									end if
								end if
							end if
						end if
					end if
				end if
			end if
		end repeat
	end tell
 
end tell

Omnifocus

applescript.txt · 最后更改: 2015/12/23 03:02 由 dr.j

Bitnami