AppleScriptBasics

[AppleScript]Dict Arrayの入れ子(ネスト)

20211009-235907


前も書いたと思うんですが…
defaults write hoge.foo.appid '{theDict = {theArray = (STRING);};}'
です

set theComandText to ("defaults write /Users/Shared/Library/Preferences/com.apple.ScriptEditor2.plist '{ \"NSToolbar Configuration Document Toolbar Identifier\" = {\"TB Item Identifiers\" = (\"NSToolbarFlexibleSpaceItem\",\"Show Event Log History Toolbar Item Identifier\",\"NSToolbarFlexibleSpaceItem\",\"Record Script Toolbar Item Identifier\",\"Stop Script Toolbar Item Identifier\",\"Run Script Toolbar Item Identifier\",\"NSToolbarFlexibleSpaceItem\",\"Check Syntax Toolbar Item Identifier\",\"NSToolbarFlexibleSpaceItem\",\"Run Script Application Toolbar Item Identifier\",\"Show View Toolbar Item Identifier\",\"NSToolbarFlexibleSpaceItem\",\"Print Toolbar Item Identifier\");};}'") as text
do shell script theComandText

ダウンロード - nest.scpt.zip

XMLで書いちゃうのもあり

set theComandText to ("defaults write /Users/Shared/Library/Preferences/com.apple.ScriptEditor2.plist \"NSToolbar Configuration Document Toolbar Identifier\" \"<dict><key>TB Item Identifiers</key><array><string>NSToolbarFlexibleSpaceItem</string><string>Show Event Log History Toolbar Item Identifier</string><string>NSToolbarFlexibleSpaceItem</string><string>Record Script Toolbar Item Identifier</string><string>Stop Script Toolbar Item Identifier</string><string>Run Script Toolbar Item Identifier</string><string>NSToolbarFlexibleSpaceItem</string><string>Check Syntax Toolbar Item Identifier</string><string>NSToolbarFlexibleSpaceItem</string><string>Run Script Application Toolbar Item Identifier</string><string>Show View Toolbar Item Identifier</string><string>NSToolbarFlexibleSpaceItem</string><string>Print Toolbar Item Identifier</string></array></dict>\"") as text
do shell script theComandText

|

[Script]ARMアップルシリコンとINTELの分岐

set objSysInfo to system info
set theCpuType to (CPU type of objSysInfo) as text

if theCpuType contains "Intel" then

(*ここにインテル処理*)
else

(*ここにM1処理*)
end if

シェル の場合は
#!/bin/sh

theARC=`/usr/bin/arch`
theINTEL="i386"

if [ $theARC = $theINTEL ]; then
echo "#####Running on INTEL"


else
echo "#####Running on ARM"


fi

こんな感じかな

ダウンロード - arch.zip


|

Function Key Codes

F1: 122
F2: 120
F3: 99
F4: 118
F5: 96
F6: 97
F7: 98
F8: 100
F9: 101
F10: 109
F11: 103

tell application "System Events"
key code XXXX
end tell

|

Read My Scripts.app (Mountain Lion は AppleScript のルールをどう変更したか)

Website_image20120812_31141


Mountain Lion は AppleScript のルールをどう変更したか


|

[system info]ipアドレスを取得する。

Image00221215_122723

■WWW側(グローバルIPアドレス)を取得する

[IP]定期的にグローバルIPアドレスを調べてメールで知らせる【applescript】[LINK]アイコン:新しいウィンドで開きます

[AppleScript]www側のIPアドレスを取得する[LINK]アイコン:新しいウィンドで開きます


■ローカル実際のアドレス



set mySystemInfo to (get system info)
IPv4 address of (mySystemInfo)

↑でも(一度system infoの全てを格納する方法)
↓でも同じ
IPv4 address of (system info)

system infoは非常に便利です。

AppleScript version (text, r/o) : the AppleScript version
AppleScript Studio version (text, r/o) : the AppleScript Studio version
system version (text, r/o) : the system version
short user name (text, r/o) : the current user’s short name
long user name (text, r/o) : the current user’s long name
user ID (integer, r/o) : the current user’s ID
user locale (text, r/o) : the current user’s locale
home directory (alias, r/o) : the current user’s home directory
boot volume (text, r/o) : the boot volume
computer name (text, r/o) : the computer name
host name (text, r/o) : the host name
IPv4 address (text, r/o) : the IPv4 address
primary Ethernet address (text, r/o) : the primary Ethernet address
CPU type (text, r/o) : the CPU type
CPU speed (integer, r/o) : the clock speed of the CPU in MHz
physical memory (integer, r/o) : the amount of physical RAM in MB


Macアドレスも取得出来ますので
管理者の方は色々使えますね。

| | コメント (0)

[SetFile]ファイルを不可視 可視 に変更する。

不可視


-----ファイルを隠す

set OpenDef to the path to desktop as alias

tell application "Finder"

set FileAlias to choose file with prompt "ファイルを選んでください" default location (OpenDef) with multiple selections allowed, showing package contents and invisibles

set PoPath to POSIX path of FileAlias

do shell script "/Developer/Tools/SetFile -a V " & PoPath


end tell

可視


-----ファイルを表示する

set OpenDef to the path to desktop as alias

tell application "Finder"

set FileAlias to choose file with prompt "ファイルを選んでください" default location (OpenDef) with multiple selections allowed, showing package contents and invisibles


set PoPath to POSIX path of FileAlias

do shell script "/Developer/Tools/SetFile -a v " & PoPath


end tell


両方とも1文字を除いて同じ
do shell script "/Developer/Tools/SetFile -a V "
do shell script "/Developer/Tools/SetFile -a v "
大文字か小文字か
の違いだけですね。


「visibles.zip」をダウンロード[Download]新しいウィンドで開きます



| | コメント (0)

[AppleScript]ランダム処理【some item to 】

自分メモ兼

set theList to {"1", "2", "3", "4", "5", "6", "7"}





set theSomeItem to some item of theList



display dialog theSomeItem buttons {"OK"} default button 1
say theSomeItem displaying theSomeItem with waiting until completion

 


Force4u00221001_73134

リストの中の『some』を握ります。

 

  
「some_list.scpt.zip」をダウンロード


 

| | コメント (0)

[Applescript]as

set someObject01 to XXXX as text
set someObject02 to XXXX as string
set someObject03 to XXXX as Unicode text
set someObject04 to XXXX as list
set someObject05 to (the path to desktop) as alias
set someObject06 to XXXX as integer
set someObject07 to XXXX as number
set someObject08 to XXXX as real
set someObject09 to "true" as constant
set someObject10 to (current date) as date
set someObject11 to "/tmp" as POSIX file
set someObject12 to {product:"A", price:100} as record
set someObject13 to (window 1) as reference
set someObject14 to {65535, 65535, 65535} as RGB color
set someObject15 to POSIX file ("/Library/Documentation/Acknowledgements.rtf") as file
単位系
set someObject51 to XXXX as centimeters
set someObject52 to XXXX as centimeters
set someObject53 to XXXX as feet
set someObject54 to XXXX as inches
set someObject55 to XXXX as kilometers
set someObject56 to XXXX as kilometers
set someObject57 to XXXX as meters
set someObject58 to XXXX as meters
set someObject59 to XXXX as miles
set someObject60 to XXXX as yards
set someObject61 to XXXX as square feet
set someObject62 to XXXX as square kilometers
set someObject63 to XXXX as square kilometers
set someObject64 to XXXX as square meters
set someObject65 to XXXX as square meters
set someObject66 to XXXX as square miles
set someObject67 to XXXX as square yards
set someObject68 to XXXX as cubic centimeters
set someObject69 to XXXX as cubic centimeters
set someObject70 to XXXX as cubic feet
set someObject71 to XXXX as cubic inches
set someObject72 to XXXX as cubic meters
set someObject73 to XXXX as cubic meters
set someObject74 to XXXX as cubic yards
set someObject75 to XXXX as gallons
set someObject76 to XXXX as liters
set someObject77 to XXXX as liters
set someObject78 to XXXX as quarts
set someObject79 to XXXX as grams
set someObject80 to XXXX as kilograms
set someObject81 to XXXX as ounces
set someObject82 to XXXX as pounds
set someObject83 to XXXX as degrees Celsius
set someObject84 to XXXX as degrees Fahrenheit
set someObject85 to XXXX as degrees Kelvin

| | コメント (0)

起動時に消去する項目

MacOS9 的には『 起動時に消去する項目』
OSXのUnix的には 『/tmp』
OSX10.6的には 『/var/folder/XXX/XXXXX/:TemporaryItems』


この中にある物は
起動時に削除されます。

AppleScriptでは

set TemporaryItemsFolder to path to temporary items

tell application "Finder"
open TemporaryItemsFolder

end tell


tell application "Finder"
activate
set startupDiskName to path to startup disk as Unicode text
set tmpPathTXT to startupDiskName & "private:tmp:" as Unicode text
set tmpPath to tmpPathTXT as alias

open tmpPath

end tell

こんな感じで指定できますね。

 

「TemporaryItems.rtf」をダウンロード[Download]DownloadFile

「TemporaryItems.scpt.zip」をダウンロード[Download]DownloadFile

| | コメント (0)

[AppleScript]日付の基本

AppleScriptでの日付の整形方法のヒント


621x437_currentdate_03

↑このような戻り値になるのは

↓書式の設定が反映されているのですが
665x292_currentdate_05

 

内部的には英語で動作しています。
621x437_currentdate_09


663x291_currentdate_08


 

そんな事になっていますので
今日の日付の変換は英語で行なえます。





set nowTime to my DateAndTIme(current date)


------------------#ここからサブルーチン
to DateAndTIme(theDate)
set y to (year of theDate)
set m to my monthNumStr(month of theDate)
set d to day of theDate
set hms to time of theDate
set hh to h of sec2hms(hms)
set mm to m of sec2hms(hms)
set ss to s of sec2hms(hms)
return (y as text) & my zero1(m) & my zero1(d)

end DateAndTIme
------------------#月表示を数字に置き換える
to monthNumStr(theMonth)
set monList to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with i from 1 to 12
if item i of monList is theMonth then exit repeat
end repeat
return i
end monthNumStr
------------------#ゼロサプレス
to zero1(n)
if n < 10 then
return "0" & n
else
return n as text
end if
end zero1
------------------#時間表示を:で分割
to sec2hms(sec)
set ret to {h:0, m:0, s:0}
set h of ret to sec div hours
set m of ret to (sec - (h of ret) * hours) div minutes
set s of ret to sec mod minutes
return ret
end sec2hms


このようにしておく事で
『ユーザーの環境設定』に左右されないって
事になりますね。

 

「yyyymmdd.rtf」をダウンロード[Download]DownloadFile

「yyyymmdd.scpt.zip」をダウンロード
[Download]DownloadFile

 

日時関係のオプションはだいたい
こんな感じ


tell current application

set DateAndTIme to my (current date)

set nowYear to my year of (current date)

set nowMonth to the month of (current date)

set nowMonthNo to the month of (current date) as number

set nowDay to the day of (current date)

set nowWeekday to the weekday of (current date)

set nowWeekdayNo to the weekday of (current date) as number

set nowHours to the hours of (current date)

set nowMinutes to the minutes of (current date)

set nowSecond to the seconds of (current date)

set nowTime to the time of (current date)

set nowDateString to the date string of (current date)

set nowTimeString to the time string of (current date)

set nowDateList to the {year, month, day} of (current date)

set nowDay to the (DateAndTIme) + (2 * days)

set nowDay to the (DateAndTIme) + (2 * hours)

end tell

戻り値は実際に試してみてください。

 

例えば24時間後を求めるなら

tell current application

set DateAndTIme to my (current date)
set nowDay to the (DateAndTIme) + (24 * hours)

end tell


60日後
って事なら

tell current application

set DateAndTIme to my (current date)
set nowDay to the (DateAndTIme) + (60 * days)

end tell

になります。


 

「now.rtf」をダウンロード[Download]DownloadFile

「now.scpt.zip」をダウンロード[Download]DownloadFile

 

日付だけでなく
時間も入れたい場合は
このようになりますね。




set nowTime to my DateAndTIme(current date)


--------------------------------------------------#ここからサブルーチン
to DateAndTIme(theDate)
set y to (year of theDate)
set m to my monthNumStr(month of theDate)
set d to day of theDate
set hms to time of theDate
set hh to h of sec2hms(hms)
set mm to m of sec2hms(hms)
set ss to s of sec2hms(hms)
return (y as text) & my zero1(m) & my zero1(d) & "_" & zero1(hh) & zero1(mm) & zero1(ss)

end DateAndTIme
------------------#月表示を数字に置き換える
to monthNumStr(theMonth)
set monList to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with i from 1 to 12
if item i of monList is theMonth then exit repeat
end repeat
return i
end monthNumStr
------------------#ゼロサプレス
to zero1(n)
if n < 10 then
return "0" & n
else
return n as text
end if
end zero1
------------------#時間表示を:で分割
to sec2hms(sec)
set ret to {h:0, m:0, s:0}
set h of ret to sec div hours
set m of ret to (sec - (h of ret) * hours) div minutes
set s of ret to sec mod minutes
return ret
end sec2hms


 


「yyyymmdd_hhmmss.rtf」をダウンロード[Download]DownloadFile

「yyyymmdd_hhmmss.scpt.zip」をダウンロード[Download]DownloadFile

 


デスクトップフォルダに『今日の日付』のフォルダ作ったり

今日の日付のファイル名に変更したり


色々工夫できますね。




set nowTime to my DateAndTIme(current date)

tell application "Finder"
try
make new folder at (path to desktop folder from user domain as alias with folder creation) with properties {name:nowTime}
end try
end tell

--------------------------------------------------#ここからサブルーチン
to DateAndTIme(theDate)
set y to (year of theDate)
set m to my monthNumStr(month of theDate)
set d to day of theDate
set hms to time of theDate
set hh to h of sec2hms(hms)
set mm to m of sec2hms(hms)
set ss to s of sec2hms(hms)
return (y as text) & my zero1(m) & my zero1(d)

end DateAndTIme
------------------#月表示を数字に置き換える
to monthNumStr(theMonth)
set monList to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with i from 1 to 12
if item i of monList is theMonth then exit repeat
end repeat
return i
end monthNumStr
------------------#ゼロサプレス
to zero1(n)
if n < 10 then
return "0" & n
else
return n as text
end if
end zero1
------------------#時間表示を:で分割
to sec2hms(sec)
set ret to {h:0, m:0, s:0}
set h of ret to sec div hours
set m of ret to (sec - (h of ret) * hours) div minutes
set s of ret to sec mod minutes
return ret
end sec2hms

 


「yyyymmdd__make_folder.scpt.zip」をダウンロード[Download]DownloadFile

「yyyymmdd__make_folder.scpt.rtf」をダウンロード[Download]DownloadFile


 
ワンポイントで
月番号

曜日番号

as number
とする事で数値でも表示されます。


Screencapture00220810_12400jst


Screencapture00220810_12411jst

 

でも

do shell script "date '+%Y%m%d_%k%M%S'"

Force4u00220930_222435

ってしちゃうのが
一番早いね......笑

| | コメント (0)

その他のカテゴリー

Accessibility AccessibilityCheck AccessibilityForm AccessibilityInDesign AccessibilityPDF Acrobat Acrobat Action Acrobat Annotation Acrobat AppleScripts Acrobat Character Acrobat Layer Acrobat PDF Embed API Acrobat PDF Form Print Acrobat Plug-ins Acrobat Portfolios Acrobat Print AcrobatBarcode AcrobatDialog AcrobatForm AcrobatJS AcrobatMenu AcrobatPDF AcrobatStamp AcrobatYouTube AddressBook Adobe Adobe InDesign Adobe Photoshop AdobeAppleScript AdobeBridge AdobeIllustrator AdobeJSX aed Alfresco Android AnimationGif Apple Apple Support AppleScript AppleScriptBasics AppleScriptCharacter AppleScriptColor AppleScriptDroplet AppleScriptErrorNum AppleScriptFolder AppleScriptFontBook AppleScriptRename AppleScriptTools AppleSymbols Applications Barcode Barcode2D BarcodePostal BetterHTMLExport Book BOX Browser buzz Certificates CharacterEntity CharacterSets Colors Cool Site CSS Cutting DecoMail DecorationMail Design Desktop Diff DJ dmg DNS Documents Download DTP eBook Editer eMail Envelopes ExifTool Facebook FFmpeg File System Fonts FontsTool FontsWeb FOOD FormPrint ftp Gadget Gif Animation Google Google Chrome Enterprise HexEditor HTML info iPhoto ISBN ISO iTunes iWork iWorkNumbers iWorkNumbersCalendar iWorkNumbersTimecard iWorkPages JavaScript JeditX JeditX Regexp JeditXAppleScript JIS jquery Letterpress Library logo Mac Admin Mac Archiver Mac Browser Mac Browser Plugin Mac QuickLook Mac Setup Mac Spotlight Mac Video Map Memo Microsoft Teams Mobby mobileconfig Moto Movies Music Network Basic ntp OCR Office OfficePowerPoint OSX Paint Pantone Paper PDFlib Permission Photo Pictograms Print Public Python QuickLook QuickTime QuickTimeSetting QuickTimeSound Real Media ReName ResourceFork ruby Sample Screen ScreenCast Search Security SEO Sharing SLAResource Sound Spotlight Stamp SWF TCC.db Tutorial PSD TV Twitter Typography Unicode Utilities Video WEB APP WebFont Wedding Windows WindowsMedia XML XMP XPS YouTube YouTube Rss