トップ «前の日記(2018-09-14) 最新 次の日記(2018-10-01)» 編集

Cocoa練習帳

iOS/iPhone/iPad/watchOS/tvOS/MacOSX/Android プログラミング, Objective-C, Cocoa, Swiftなど

2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|

2018-09-15 [cocoa][swift]AppleScriptとは何ぞや

スマートフォン・エンジニアにとって、macOSはOfficeが動くUNIXという利点があり、シェル・スクリプトを利用した自動化に威力を発揮している。ただ、macOSにはMacintosh時代からのAPpleScriptがあり、これを利用しない手はない。
自動化したけど、アラートが表示されていて失敗したという悲しいトラブルも、これで回避できるかも!?

シェルスクリプトとして実行する

#!/usr/bin/osascript
display dialog "Welcome to AppleScript."

シェルスクリプトからAppleScriptをよぶ

#!/bin/sh
osascript -e 'display dialog "Welcome to AppleScript."'

AppleScriptからシェルスクリプトを呼ぶ

set fileInfo to do shell script "cd ~; ls" 
display dialog fileInfo 

最前面のアプリを終了させる

#!/usr/bin/osascript
 
tell application "System Events"
    set fullname to name of (path to frontmost application)
end tell
 
set savedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set front_app to items 1 thru -2 of text items of fullname as text
set AppleScript's text item delimiters to savedDelimiters
 
if front_app is "Firefox" then
    tell application "Firefox"
        quit
    end tell
end if

最前面のアプリのダイアログを改行キーで閉じる

#!/usr/bin/osascript
 
tell application "System Events"
    set fullname to name of (path to frontmost application)
end tell
 
set savedDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set front_app to items 1 thru -2 of text items of fullname as text
set AppleScript's text item delimiters to savedDelimiters
 
if front_app is "Firefox" then
    tell application "System Events"
        keystroke return
    end tell
end if

トップ «前の日記(2018-09-14) 最新 次の日記(2018-10-01)» 編集