2016-11-01 2 views
0

현재 사용자가 iCloud Documents를 사용할 수있는 경우 Mac 컴퓨터에서 찾으려고합니다. 이 위치에있는 plist (MobileMeAccounts.plist)를 찾았지만 사용 가능 여부를 식별 할 수있는 스크립트를 만드는 데 도움이 될 수 있습니다.plist 파일에서 여러 문자열을 찾을 수있는 스크립트

내가 특별히 다음과 같은 코드를 찾고 있어요 사실 일 수 있습니다 : 여기

<key>Enabled</key> 
<true/> 

는 PLIST입니다. 아래로 스크롤하면 활성화 된 "MOBILE_DOCUMENTS"가 표시됩니다.

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
<key>Accounts</key> 
<array> 
    <dict> 
    <key>AccountAlternateDSID</key> 
    <string>99999999</string> 
    <key>AccountDSID</key> 
    <string>999999</string> 
    <key>AccountDescription</key> 
    <string>iCloud</string> 
    <key>AccountID</key> 
    <string>*****@gmail.com</string> 
    <key>AccountUUID</key> 
    <string>9999999</string> 
    <key>DisplayName</key> 
    <string>User Name</string> 
    <key>LoggedIn</key> 
    <true/> 
    <key>Services</key> 
    <array> 
     <dict> 
      <key>Name</key> 
      <string>CLOUDDESKTOP</string> 
      <key>ServiceID</key> 
      <string>com.apple.Dataclass.CloudDesktop</string> 
      <key>status</key> 
      <string>active</string> 
     </dict> 
     <dict> 
      <key>Name</key> 
      <string>FAMILY</string> 
      <key>ServiceID</key> 
      <string>com.apple.Dataclass.Family</string> 
      <key>showManageFamily</key> 
      <true/> 
     </dict> 
     <dict> 
      <key>Enabled</key> 
      <true/> 
      <key>Name</key> 
      <string>MOBILE_DOCUMENTS</string> 
      <key>ServiceID</key> 
      <string>com.apple.Dataclass.Ubiquity</string> 
      <key>apsEnv</key> 
      <string>production</string> 
      <key>authMechanism</key> 
      <string>token</string> 
      <key>url</key> 
      <string>https://p48-ubiquity.icloud.com:443</string> 
      <key>wsUrl</key> 
      <string>https://p48-ubiquityws.icloud.com:443</string> 
     </dict> 
+1

파일이 잘 렸습니다 !! awk는 xml을 분석하는 데 가장 좋은 도구가 아닙니다. –

+0

잡기에 감사드립니다! 나는이 정보를 파싱 할 수있는 방법을 공개한다. awk 일 필요는 없습니다. 감사. – Dan

답변

0

Python에는 plists를 구문 분석하기위한 모듈이 포함되어 있습니다. 아마도 더 나은 오류 검사를 원할 것입니다. :

$ cat parseplist.py 
import plistlib 
pl = plistlib.readPlist("the_plist.xml") 
print pl['Accounts'][0]['Services'][2]['Enabled'] 

$ python parseplist.py 
True 
관련 문제