Writing to derived data in an archived app - macos

I produced a .aiff file in my app and it's in my derived data folder, somewhere deep in the /Library. When I run the app in Xcode everything works fine. However when I archive it, the program crashes when it tries to write. How do I solve this? Do I need to learn to use Core Data or is there a easy fix?

Are you trying to write to the current working directory?
(If you're trying to do something like [foo writeToFile:#"output.aiff" …], you are.)
When you run within Xcode, the CWD is the build products directory within DerivedData where your application's bundle gets created.
When you run outside of Xcode, the CWD is the root of the startup disk, which you do not ordinarily have write access to and should never touch without explicit orders and permission to do from the user (via an Open panel or similar).
Either way, the CWD is the wrong place to put things.
You probably should run a Save panel, then write the file in your completion handler to the URL the Save panel has for you.
If you want to stash the file in some constant directory, ask an NSFileManager for the Caches folder in the user domain (~/Library/Caches), then tell it to create a folder inside that folder whose name is your main bundle's bundleIdentifier, then write the file in that directory.

Related

Automator - Set a variable with the current path of my workflow app

I created this Automator app that creates the folders I need to start a new project, but I need to share it with my team, so instead of telling them to open Automator and set the path (doucments/projects/2020/) by themself. I was thinking that maybe they just can paste it in the 2020 folder, run the app and create the project folders in the same folder.
But I don't know how to set a variable with the current path where my Automator App it's saved. Any ideas? Thanks, guys!
My current workflow
To create a new folder in a specific location of the user's home folder, you can use the the special 'location' variables that automator defines. Click the variables tab button in the upper left corner of the automator window to see the full list of available variables...
So, to create a folder hierarchy like the one shown in the link, but at a standardized location in the documents folder, use a flow like the following:
Since Automator doesn't have a specific variable that gives the location of the created workflow app, if you want a path relative to the app's location you'd use a Run AppleScript action and try to path to me command, but every time I've tried it I've received weird errors which make me think that command doesn't work correctly in Automator. I mean, the following ought to produce the correct result, but it consistently errors out:
Maybe you can make it function...

How do I link directly to an alias through afp?

I'm working on an intranet web application with a file sharing server set up using AFP.
My goal is to create a link on the page that will open up Finder to a specific folder on the share network, but it has to go through an alias. I think it'd be easier to explain with an example.
For this share, there is a folder called Objects that contains a bunch of folders with unpredictable names, and a folder called Alias that contains a bunch of aliases to folders in Objects. So a link to afp://server/share/Alias/obj1 should open the folder at afp://server/share/Objects/unpredictableName, where obj1 is an alias pointing to unpredicableName.
On OSX 10.8 this works as expected, however on 10.9 and later that link opens the Finder at the Alias folder, instead of actually going into unpredictableName. What changed, and is there any way to restore the previous behavior? Thanks.

How do I get Windows shortcut "Starts In" behaviour when double-clicking on files?

I have a type of data file associated with my program. I can run my program by clicking on a shortcut, or by double-clicking on the data file. Standard Windows stuff.
However, I need to be able to set the Starts In folder to a specific folder. Everything is fine when I use the shortcut (because that has a Starts In parameter), but when I double-click on a data file, the Starts In defaults to the local folder of the data file, which is not what I want.
To be more specific, I'm using a network dongle protection system (Safenet SHK) that requires an XML file to be in the Starts In folder before the protection shell allows my code to be run, so I can't just change the folder in my program, because it hasn't run yet.
What can I do?
You could create a launcher application. This application would do nothing but set the working directory and then start the real application and pass in the name of the file the user is trying to open. Your application shortcut can point to your main application, but the file associations you create would use the launcher.

Cocoa: how to Write file inside package contents of app

When we try to delete/uninstall Cocoa .app file ,we directly move the .app file to trash.
This does not ensure the deletion of app user data folder in application support.
The user data lies there hanging. So i wanted to save the user data/ files inside application itself (app->showPacakge contents->somewhere).
If it is not possible! Any ways of clearing app user data folder in application support when user moves app to trash ?
Not a great idea.
The package content is signed. Any modification will be detected by the OS and will prevent launching of the app.
Not to mention the fact that you might not have access to the Applications folder, where most users will keep their app.
if you are using packages for installing your application, then you can have pre-install script, which deletes user data in the application support folder.

Why does my xcodeproj directory appear as a file and how do I stop it from doing that?

According to my subversion client and the command line, my xcodeproj file is actually a directory. However, trying to list the content of it from other applications such as my merge tool, it appears only as a file and prevents me from accessing the files contained within it?
What is the point of all this, where is the magic that makes it happen and how can I access the files in that directory from normal applications?
It is a bundle, and you can navigate into via command line or by right clicking and selecting show contents ... If you want it to never work as a bundle then you will have to remove that property, which I think is an extended attribute... So you will need to check out xargs.

Resources