I'm trying to script iTunes from NSAppleScript in my Cocoa app in order to add a file to the library.
In my entitlements file, I added the following:
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.itunes</key>
<array>
<string>com.apple.itunes.library.read-write</string>
</array>
</dict>
I then call the AppleScript like this:
var error: NSDictionary? = nil
let appleScript = NSAppleScript(source: "tell application \"iTunes\" to add (POSIX file \"\(path)\") to library playlist 1")
let result = appleScript?.executeAndReturnError(&error)
but it fails with an error -10004: iTunes got an error: A privilege violation occurred.
I tried capitalizing iTunes both ways (itunes and iTunes) but nothing seems to work. I also tried adding, on top of the read-write entitlement, the read entitlement. Finally, I tried adding read and write access to the user's Music folder (where the iTunes library is stored) and this didn't help either.
Is there another required entitlement that I'm not aware of in order to script iTunes?
I found this link in my search for a solution (link) but it requires the user to select a specific folder in his Library folder to give the application user-selected file access and then it requires the script to be in a separate file which is 2 things too many for what I want to do. I don't trust the user regarding the management of the script files and I don't need a file for 1 line of AppleScript code. Another disadvantage, as I understand NSUserAppleScriptTask is that you can't persist a script's state across multiple calls, which is not a problem in my case but could be for someone else.
Thanks
After contacting the Developer Technical Support of Apple, I was able to solve this problem, which is actually 2 problems in one.
First, the entitlements need to have the bundle identifiers properly cased. For iTunes, the entitlements must be like this (note the capital T in iTunes):
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.iTunes</key>
<array>
<string>com.apple.iTunes.library.read-write</string>
</array>
</dict>
Then, the privilege violation will occur unless the AppleScript code includes of source 1 at the end like this :
tell application "iTunes" to add (POSIX file "your/path/to/mp3.mp3") to library playlist 1 of source 1
There you go!
Related
About my problem: I used https://theswiftdev.com/2017/10/27/how-to-launch-a-macos-app-at-login/ for launch my mac-OS app at login it work good. After time I found some problem in my application. My app generated sqlite files like sqlite-shm, .sqlite-wal but after added changеs as "launch" it does't work now.
problems in with "App Sendbox" it included as "on" if I change to "off" my files will be create but "launch" will not be work
How to make these two features work?
Can you help my with my problem?
Ok! i found answer to my question my self)
If it well be halpfully to another peoples i will by happy.
Ok! let's start)
First we are need delete all code as this is linc (of course if you did as in this linc) and then disable the sandbox (cause it blocks kreating sql.lite files)
and second we are need add to info.plist this:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
and thats all)
I want that after installing my app from an OTA the home button of the device will not work at all so that user is unable to come out from the App. My digging led me to following results
A) I got a way to disable home button by a "mobileconfig" profile but it needs to restart the device and user have to open my app just after booting, i want to do this without restarting with something like Private Frameworks on non-Jail-broken devices. I want to know is that possible for non-jail-break devices?
C) If it is not possible to disable home button with Private Frameworks, then is there any way to open an app just after booting the device?, since certain jailbreak apps/ processes are loaded upon startup.
[NOTE: I don't want to submit my app to iTunes.]
In iOS6, there's a feature called "Guided Access", which will allow device owners to lock users (like toddlers and school kids) into an app.
This explains the Guided Access for iOS 6 apps.
The official answer of this question is "you can not disable home button in ios devices it is os level architecture and your are not authorized for it."
You need to dig to operating system flow to make any changes which might be quiet tough.
well, if you change you sight though it than there is one open and simple solution for this in ios 6 known as Guided Access.
If you are able to jailbreak your device create a LaunchDaemon or use an existing one. The LaunchDaemon is a file in plist format that is called upon rebooting and starting your device. You will also need a file named open created by K3A
Download open from here
You will need to move open to /usr/bin/ or you can put it inside your app does not matter but set permissions to 0755 and root:wheel
Now on to the LaunchDaemons, they are stored here
/System/Library/LaunchDaemons
Here is an example.
Lets say you name the LaunchDaemon
com.gauravstomar.test.plist
Where it says com.bundle.identifier put your apps identifier you may also find it in your Info.plist inside of your apps directory where it says CFBundleIdentifier
Now inside the plist insert the following information
<?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>Label</key>
<string>com.gauravstomar.test</string>
<key>ProgramArguments</key>
<array>
<string>open</string>
<string>com.bundle.identifier</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>1</integer>
</dict>
</plist>
Label has to be the same name as the LaunchDaemon.plist excluding plist extension
ProgramArguments is what calls the file open and launches the app
RunAtLoad makes this plist launch upon reboot
StartInterval will make the LaunchDaemon.plist open back up after 1 second if the user exits the app, if the user is still in the app nothing will happened
Make sure the permissions for your LaunchDaemon is set to
0644 root:wheel
You can still use your mobileconfig so that the home button is disabled. Once assessment is complete you can disable the LaunchDaemon so that the app stops relaunching itself with the following command
launchctl unload/System/Library/LaunchDaemon/com.gauravstomar.plist
Let me know if you need any more help.
Without jailbreaking, the app is sandboxed. The app simply does not have access to mess with the home button. And you really shouldn't be messing with the home button.
In addition to "Guided Access", you can also make use of "Restrictions", which will allow you to disable everything accept opening your app. You can disable Apple specific apps including Safari, and prevent users from installing apps, deleting apps, making purchases, etc...
We have a number of iPod touches with a ticket scanning app we rent out to our customers. We make use of "Restrictions" to disable everything besides our app. The most helpful restriction thus far is preventing people from deleting apps - It's incredible how many people will accidentally delete an app, even after the warning prompt.
I would like to import vCards into my iOS app using the mail app. I have added public.vcard to my projects plist. If I try to open the vcard in another app using the UIDocumentInteractionController everything works as expected. However if I try to open the vCard in the mail app, the vCard is opened in the mail with no choice for my app. Is there a solution?
UPDATE:
The plist entry for the vcard looks like
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>vCard</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>LSItemContentTypes</key>
<array>
<string>public.vcard</string>
</array>
</dict>
</array>
This entry looks rather incomplete to me. Generally if yor application is able to open certain types you need to have either an import declaration (if the file format is owned by another application) or an export declaration (if the format is owned by your)
iOS and Mac are matching UTIs mostly by extension, so I guess you also need to have that in the declaration. Check with the UTI functions on iOS is there is indeed the public.vCard type assigned to your file's extension. If not, then it cannot be found.
I would add an UTImportedTypeDeclarations to your plist if there is such an association, if not add an UTExportedTypeDeclarations
I wrote this tutorial to explain all the things you need: http://www.cocoanetics.com/2012/09/fun-with-uti/
This seems to be impossible as of iOS 7.0.4.
iOS seems to handle some file types within the Mail app differently than others. Within the Mail app you won't get the option to open those file types in apps that are not from Apple.
You can verify this by using the UIDocumentInteractionController to open a file programmatically. This will prompt the user to open the file in a lot of apps (in all apps that registered this file type or a more general one. The Dropbox app e.g. almost opens everything).
When you mail yourself the exact same file and try to open it within the Mail app you'll not get those options (like Dropbox).
I verified this by registering VCard/.vcf, Jpegs and a custom type.
There is iPhone app "Another Mail Client" that should be able to open any file to send it as attachment. So, I want to associate this application with any file with any extension.
Following the documentation, we should declare support for files with the root UTI-type public.data – any file should belong to this type. It works, but not at all. In this case, our app will not be able to open any file, but only those which have already been registered in the system. For example, if in any application (e.g., dropbox) we'll try to "open in..." file with an unknown extension (file.unknowntype) using UIDocumentInteractionController, then the answer will be negative despite the fact that we have already registered our application and it supports the root UTI-type public.data. But, if you install another application, which supports files with extension (*.unknowntype), then our application will also be able to open these files and will appear in "open in..." application list.
UPD: #Gabriel This is CFBundleDocumentTypes part of my info.plist file:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>MyMail</string>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Default</string>
<key>CFBundleTypeIconFiles</key>
<array>
<string>Icon29.png</string>
...
<string>Icon114.png</string>
</array>
</dict>
</array>
I've made an app with the following setup
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>name</string>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
</array>
</dict>
</array>
When I try to open a .pdf from Safari, this app shows up in "open in.." list. Can you make a sample app and try it?
UPD:
It seems like claim 'public.data' (tried also public.item, public.content) means file, which belongs to set "all known to system UTIs", not any file. So, you will be able to handle 99% of files, which users want to send by email , but not all. Another way would be to export UTI that you think are important, but which are not in system UTIs by default.
Friend, I read your question properly before posting the answer. I gave another thought that you will have a set of already known "any types" of files to register in a bulk. However, you want to dynamically accommodate your app to register any file type given to your app in future and make it attachable. For this as far as my knowledge is concerned, you cannot make you app to universally support any unknown file type. Let me explain what happens,
Suppose you make an application APP1 then it does not know about a file extension .XYZ and install it on iPhone.
But, later I develop another application APP2, which contains the above code and I register the .XYZ type from APP2 in whatever iPhone it installs.
So, lets say I install APP2 in your iPhone, having APP1. And when my app runs, then the .XYZ extension ( known to APP2 ahead of time) gets registered into the iPhone.
This is the reason now your app APP1 can use this .XYZ file surprisingly.
Concluding, you have to know a specific type of extensions ahead of time before making the app.
However, heres a possible solution for it.
Solution :
Decide the maximum number of characters you want to support in an extenstion. Lets say 4.
Now you can make a small Brute-Force routine to run in your app to make all the possible character combinations and register them all. This should make any file with extension upto 4 characters attachable to mail.
I hope that should do the trick.
Best of luck!
An idea for investigation...
If the installation of another app "fixes" the problem then try inspecting the other apps Info.plist file to see if it is registering or exporting any interesting UTIs or similar settings.
It sounds like your app might only be doing half the job and the other app is completing the missing setup.
You can inspect the contents of an apps ipa file from iTunes by copying it, renaming ipa to zip extracting the contents and then Show Package Contents on the app inside.
I am trying to figure out how to copy a ringtone file (.m4r) embedded in the app to iTunes when connected. After the file is copied into iTunes, they can simply sync the file like every other file. I know this is possible, since there are other ringtone apps that do this exact same thing. If someone could point me in the right direction or maybe provide some sample code, that would be great. Thanks.
You can share files from your app's Documents directory with iTunes. Simply add the following XML to your info.plist:
<key>UIFileSharingEnabled</key>
<true/>
Now, files in your app's Documents directory will appear in the File Sharing section of iTunes. Is that what you're after?