Get a specific attribute from XML file using Ansible xml module - xpath

I have an XML file as below
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>p4v</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2018.2</string>
<key>CFBundleVersion</key>
<string>2018.2/1666551</string>
<key>CFBundleGetInfoString</key>
<string>2018.2, Copyright 2018 Perforce Software, Inc.</string>
<key>CFBundleIconFile</key>
<string>application.icns</string>
<key>P4RevString</key>
<string>P4V/MACOSX1013X86_64/2018.2/1666551 (2018/05/30)</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
<key>CFBundleName</key>
<string>P4V</string>
<key>CFBundleSignature</key>
<string>P4VC</string>
<key>CFBundleIdentifier</key>
<string>com.perforce.p4v</string>
</dict>
</plist>
How can I get the string 2018.2 for key CFBundleShortVersionString?
I have tried something like below but its listing all string values instead of one matching the provided key.
- xml:
path: /Applications/p4v.app/Contents/Info.plist
xpath: /plist/dict[starts-with(key,'CFBundleShortVersionString')]/string
attribute: CFBundleShortVersionString
content: 'text'
register: p4v_version
I think I am providing the wrong xpath here, but I couldn't find the correct one.

You don't need attribute here at all, and if there are no other <dict>-s, you can leave out the first condition.
- xml:
path: /Applications/p4v.app/Contents/Info.plist
xpath: /plist/dict/key[.='CFBundleShortVersionString']/following-sibling::*[1]
content: 'text'
register: p4v_version

Related

Info.plist couldn't be read because it isn't in the correct format

My question is about getting this error when opening Info.plist file:
Info.plist couldn't be read because it isn't in the correct format
when opening from vs for mac or xcode also, what could be wrong with tha plist file? here is my plist file so you can have a look.
<?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>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>MinimumOSVersion</key>
<string>10.3</string>
<key>CFBundleName</key>
<string>MovesaGarantias</string>
<key>CFBundleDisplayName</key>
<string>MovesaGarantias</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.MovesaGarantias</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Can we use your location at all times?</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Can we use your location when your app is being used?</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Can we use your location at all times?</string>
<key>NSCalendarsUsageDescription</key>
<string>Needs Calendar Permission</string>
<key>CFBundleIconFiles</key>
<array>
<string>Icon-60#2x</string>
<string>Icon-60#3x</string>
<string>Icon-76</string>
<string>Icon-76#2x</string>
<string>Default</string>
<string>Default#2x</string>
<string>Default-568h#2x</string>
<string>Default-Portrait</string>
<string>Default-Portrait#2x</string>
<string>Icon-Small-40</string>
<string>Icon-Small-40#2x</string>
<string>Icon-Small-40#3x</string>
<string>Icon-Small</string>
<string>Icon-Small#2x</string>
<string>Icon-Small#3x</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>XSLaunchImageAssets</key>
<string>Resources/Media.xcassets/LaunchImages.launchimage</string>
</dict>
</plist>
Error also says that the tag Key is unsopported on Xamarin vs for Mac.
I think the problem is that you have an array for a value, but no key on line 34:
<key>NSCalendarsUsageDescription</key>
<string>Needs Calendar Permission</string>
<array>
<string>Icon-60#2x</string>
Before the <array> tag, you need to have a <key>Keyname</key> entry.
Now that you've corrected your plist file, it is valid and opens just fine in Xcode:

Make an app (OSX) be able to be used in "open with" submenu

I made an application with Unity for OSX to open and modify images. Now, I want to be able able to open a file with it by using "open with". I managed to make the app appear in that submenu, but it won't open : I get an error from the os saying my app can't open the file. I really don't know why, I have no background whatsoever in OSX, and I didn't find any help on the web.
My goal is to retrieve the path of that file looking into the command line's arguments.
This is how the info.plist looks like :
<?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>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>StereoMacBuild</string>
<key>CFBundleGetInfoString</key>
<string>Unity Player version 2017.3.1f1 (fc1d3344e6ea). (c) 2018 Unity Technologies ApS. All rights reserved.</string>
<key>CFBundleIconFile</key>
<string>PlayerIcon.icns</string>
<key>CFBundleIdentifier</key>
<string>com.Company.ProductName</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
<key>CFBundleName</key>
<string>StereoProto</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>0</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>PlayerApplication</string>
<key>UnityBuildNumber</key>
<string>fc1d3344e6ea</string>
<key>LSMinimumSystemVersion</key>
<string>10.9.0</string>
</dict>
</plist>
Thanks to anyone taking some time to help me !

Couldn't parse contents of 'myapp/Info.plist'

I'm getting the following error
(null): couldn't parse contents of 'myapp/Info.plist': The data couldn’t be read because it isn’t in the correct format.
The following is the complete plist file.The program compiles and runs.I don't know why XCODE is showing this error.Please advice.
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017 me. All rights reserved.</string>
<key>NSMainStoryboardFile</key>
<string>Main</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>tranzporthub.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
</dict>
</plist>
The string value after the key CFBundleIconFile is empty. This may be your problem. Try adding an app icon file to your project and be sure this file name is included here

How can I make macOS realize my app is a web browser?

I'm trying to make an app that can handle http and https URL schemes, so that when you open System Preferences > General, my app will be listed in the dropdown for "Default web browser." Everything I can find seems to say that I just need my Info.plist to include the correct CFBundleURLTypes values to handle the URL schemes I'm interested in.
I believe I'm doing everything right, and I've compared my own Info.plist to other web browsers that show up in that list, but for some reason I can't get my own to appear there. Any idea what I'm doing wrong?
Here's my Info.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict><key>NSHighResolutionCapable</key>
<string>True</string>
<key>CFBundleIdentifier</key>
<string>com.micahflee.porcupine</string>
<key>CFBundleName</key>
<string>Porcupine</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>LSBackgroundOnly</key>
<string>0</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleDisplayName</key>
<string>Porcupine</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>Web site URL</string>
<key>CFBundleURLSchemes</key>
<array>
<string>http</string>
<string>https</string>
</array>
</dict>
</array>
<key>CFBundleShortVersionString</key>
<string>{{VERSION}}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleExecutable</key>
<string>MacOS/porcupine</string>
</dict>
</plist>

CFBundleTypeIconFile Icon not showing for given file extension

I have the following Info.plist for my application, the problem is files i save with the extension myapp do not seem to pick up on my MyApp icon which i have created from an icon set (application correctly uses icon) so guessing there is something wrong in the plist.
I am assuming if I got this working when running my application at some point documents that I have save will suddenly show with the given icon.
Incase this matters, the document is saved from a set of NSCoder based classes. Clicking these documents also opens my application and loads the file correctly, so confused what I am missing to get Icon to show on the files....
<?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>myapp</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>MyApp</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>ASWM</string>
</array>
<key>CFBundleTypeName</key>
<string>MyApp project file</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>MyApp</string>
<key>CFBundleIdentifier</key>
<string>com.workmonkeys.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>ASWM</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2012 Me. All rights reserved.</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
Turns out the system must have cached a old copy of the plist when I initially created my application. All that was needed was to rebuild the launch services database.
I used the lsregister command as documented here...
http://www.tuaw.com/2009/06/11/terminal-tips-rebuild-your-launch-services-database-to-clean-up/
Rerun the application and bingo the documents now have the respective icon associated.

Resources