开发者

is it possible to locate file on Mac without knowing exact location?

开发者 https://www.devze.com 2023-04-02 08:03 出处:网络
I am trying to locate a file on Machintosh without knowing exact file location. I am developing an app which needs to locate iTunes library XML 开发者_开发知识库file and parse it for data. However XML

I am trying to locate a file on Machintosh without knowing exact file location. I am developing an app which needs to locate iTunes library XML 开发者_开发知识库file and parse it for data. However XML resides in,

/Users/**Current logged in username**/Music/iTunes 

Now username may change, So how to set path of let my code find below named file programmatically. Language used is Objective - C.

File name : iTunes Music Library.xml

Possible solution I thought is to get username by code. Is there any method which returns a string of current logged in user's "username".

Thanks


You should be able to use ~/Music/iTunes. ~ represents the home directory of the current user.

Or you could could see this question: Mac OS X: Get current username and home directory for current user from Directory Services


Don't do this! The user's iTunes library doesn't have to be in the default location.

Instead, read the iTunesRecentDatabasePaths key from com.apple.iapps. It'll give you an array that represents the recently used iTunes libraries.

$ defaults read com.apple.iapps iTunesRecentDatabasePaths
(
    "/Volumes/Media/iTunes/iTunes Library.xml"
)


NSHomeDirectory() is a Foundation function that returns an NSString of the path to the current user's home directory.

Apple Developer Library - NSHomeDirectory

0

精彩评论

暂无评论...
验证码 换一张
取 消