-
Notifications
You must be signed in to change notification settings - Fork 0
/
plist handler.applescript
73 lines (57 loc) · 1.69 KB
/
plist handler.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(*
parseAndRetPlistEntryFromFile
http://piyocast.com/as/archives/957
extractInfoPlistAndFindString
http://piyocast.com/as/archives/3034
*)
set bID to "com.yourcompany.name" --example
(*
set appName to name of me
set bID to id of application appName
*)
plistWrite(bID, "id", "veadar")
plistRead(bID, "id")
-- result -> "veadar"
plistDelete(bID, "id")
plistRead(bID, "id")
-- result -> ""
on plistWrite(bID, theKey, theValue)
set shellText to "defaults write " & bID & " '" & theKey & "' -string '" & theValue & "'"
do shell script shellText
end plistWrite
on plistRead(bID, theKey)
set shellText to "defaults read " & bID & " '" & theKey & "' | native2ascii -reverse -encoding UTF-8"
do shell script shellText
end plistRead
on plistDelete(bID, theKey)
set shellText to "defaults delete " & bID & " " & quoted form of theKey
do shell script shellText
end plistDelete
on plistAllDelete(bID)
set shellText to "defaults delete " & bID
do shell script shellText
end plistAllDelete
--PlistファイルをParseしてレコードにして返す
on parseAndRetPlistEntryFromFile(aFile)
set f to POSIX path of aFile
set res to {}
try
tell application "System Events"
set plif to property list file f
set pitm to every property list item of plif
repeat with p in pitm
set end of res to {name, value} of p
end repeat
end tell
on error
return {}
end try
return res
end parseAndRetPlistEntryFromFile
--指定のInfoPlist(たぶん)をextractして指定文字列を含んでいるかチェック
on extractInfoPlistAndFindString(aFile, findStr)
set aPosix to quoted form of POSIX path of aFile
set a to (do shell script "/usr/bin/plutil -p " & aPosix)
set b to (a contains findStr)
return b
end extractInfoPlistAndFindString