This is provided for anyone interested in using NSFileManager to copy a file from your Project Resources to a newly created folder in the user’s Application Support folder. Specifically, there exists a database file entitled yoyo.db that I have copied into my Project Resources. This database will be accessed by the application throughout the app’s run, so I want to copy it over to the user’s Application Support Folder into a folder entitled Yoyo.
This is freshly generated code that I finished late last night. It is not optimized for efficiency, so please keep that in mind when you feel compelled to make a comment:
property database_Location : (POSIX path of (path to application support from user domain) & "Yoyo/yoyo.db")
tell current application's NSFileManager to set fileManager to defaultManager()
if fileManager's fileExistsAtPath_(database_Location) then --check for file then
log "Yes - file is there"
else
log "No - file is not there"
set theBundle to current application's NSBundle's mainBundle()
set resource_db_Path to theBundle's pathForResource_ofType_("yoyo", "db")
if fileManager's fileExistsAtPath_isDirectory_((POSIX path of (path to application support from user domain) & "Yoyo"), missing value) then --check for folder
log "But, Folder is there"
--Folder exists, but database file needs to be copied.
set db_Copied to fileManager's copyItemAtPath_toPath_error_(resource_db_Path, database_Location, missing value)
if db_Copied as boolean is true then log "FINALLY!!"
else
log "No Folder or file"
--Need to create folder AND copy db here
set folder_made to fileManager's createDirectoryAtPath_withIntermediateDirectories_attributes_error_((POSIX path of (path to application support from user domain) & "Yoyo"), false, missing value, missing value)
if folder_made as boolean is true then
set db_Copied to fileManager's copyItemAtPath_toPath_error_(resource_db_Path, database_Location, missing value)
if db_Copied as boolean is true then log "Total workage!!"
end if
end if
end if