关于AppleScript的一些应用总结
总结一下工作中常用到的一些可提升效率的一些AppleScript的操作
iTerm2
新建窗口并执行shell指令
tell application "iTerm"
set myterm to create window with default profile
tell myterm
activate current session
launch session "Default Session"
tell the current session
write text "echo hello"
write text "clear;"
write text "date && cal" without newline
end tell
write (sessions of current tab) text linefeed
end tell
end tell
新建tab, 并执行shell命令
tell application "iTerm"
tell current window
create tab with default profile
tell current session
write text "echo 'hello world~ ' "
end tell
end tell
end tell
配合自动操作选中Podfile
文件增加快速操作菜单,创建新窗口并执行pod install
#新建窗口,选中Podfile 右键快速操作找到pod install这个菜单执行即可
PodfilePath="${1%/*}"
osascript <
Safari
使用Safari打开指定URL
function openWebLink(){
osascript <
Safari当前标签页执行一段js
//CSDN或360Doc解锁文本
tell application "Safari" to do JavaScript "javascript:window.oncontextmenu=document.oncontextmenu=document.oncopy=null; [...document.querySelectorAll('body')].forEach(dom => dom.outerHTML = dom.outerHTML); [...document.querySelectorAll('body, body *')].forEach(dom => {['onselect', 'onselectstart', 'onselectend', 'ondragstart', 'ondragend', 'oncontextmenu', 'oncopy'].forEach(ev => dom.removeAttribute(ev)); dom.style['user-select']='auto'; dom.style['-webkit-touch-callout']='auto'; dom.style['-webkit-user-select']='auto'; dom.style['-ms-user-select']='auto';dom.style['-khtml-user-select']='auto'; dom.style['-moz-user-select']='auto';});" in document 1
Xcode
Xcode打开/编译/运行项目的shell工作流
#! /bin/bash
WorkspaceName="xxx.xcworkspace" #workspace文件名
FilePath="/xxx/xxx" #项目根目录路径
#打开项目
function LoadProject() {
osascript <
Finder
获取当前选中的文件或者文件夹的路径 (Mac 升级Big Sur之后Alfred快捷键就无法获取选中的文件或目录的路径,困扰了很长一段时间,后来无意中发现了这个操作,所以又算是修复了这个问题)
#! /bin/bash
# 获取当前选中的文件或者文件夹路径
CurrentSelectPath=$(osascript <