Use Applescript to pull PDF attachments out of a note - ios

I am adding several PDF documents to a note using the scan documents feature in Notes on my iPhone. I want to pull those attachments to a folder on my mac. I have the notes on iCloud so the note attachments are available. I can drag and drop, of course, but I want to automate the process. I tried to record my activity through automater and Scropt Editor, but they didn't pick up the drag and drops. I have moved to writing my own apple script.
I tried a number of approaches to the duplicate. I am able to get the path to the destination folder and can reference the items in the folder. The usage of the duplicate verb in Notes eludes me.
tell application "Finder"
set FWsimple to front window
set FW to (POSIX path of (target of front window as alias))
end tell
tell application "Notes"
set theAttachment to attachment id "x-coredata://EDDBBF66-DC2A-4A84-8913- 4548B5AA5D6C/ICAttachment/p2176"
set allAttachments to get every attachment of note "Patients 5/17/22"
duplicate the attachment to FW
end tell
{FWsimple, FW, theAttachment, allAttachments}
Running the above with the duplicate statement commented out gives me the following, so I know I am getting the objects. The front window target will be changed later, but it works for now to get the correct folder.
{Finder window id 2573 of application "Finder",
"/Users/sholland/Desktop/Applescript of Notes/",
attachment id "x-coredata://EDDBBF66-DC2A-4A84-8913-4548B5AA5D6C/ICAttachment/p2176" of application "Notes",
{attachment id "x-coredata:...p2034" of application "Notes"}
}
When I run I get: error "Notes got an error: Can’t make "/Users/sholland/Desktop/Applescript of Notes/" into type location specifier." number -1700 from "/Users/sholland/Desktop/Applescript of Notes/" to location specifier. I've tried using FWsimple and FW as the location specifier.
Please tell me how to use duplicate to copy the PDF to a folder.

Related

cordova-plugin-file: files not accessible after app update (iOS)

I am experiencing a funny problem: I am developing an ionic app, using cordova-plugin-file to store images. The resulting paths (URIs in form file:///...) are stored in a SQLite DB along with more information. When I install the app and use it, all works perfect. But if I update (or reinstall) the app, the old images are not found anymore, while newly added images work perfect.
I first suspected that the image files were being deleted on update, but I checked the content of the directory and the files are still there. (FYI: I am using file.dataDirectory/scans/ to place my files).
Then I thought that maybe I could go around the problem loading into img src a base64 blob loaded with cordova.file.readAsUrl(), but cordova.file does not find the file as well (I insist, the files are there, I checked with XCode).
So I checked further with cordova.file and it only finds files that are added after last app install, but the older files are still present in the directory.
Here my code:
private getImgSrcFromDocument(doc: Document): any {
const uri = doc.fileName;
const src = this.webView.convertFileSrc(uri);
const sanitized = this.sanitizer.bypassSecurityTrustUrl(src);
console.log({uri, src, sanitized});
return sanitized;
}
<img class="document_thumbnail" [src]="getImgSrcFromDocument(doc)">
I have already checked this, but is not my case.
By the way, the same code works perfect on Android.
Any idea what could be the problem?
Thanks in advance!
I found the reason why and the solution (very obvious when you know the problem):
Reason
On every new install, iOS renames the data directory for the app. The directory path has this form:
file:///var/mobile/Containers/Data/Application/ABC0000-1234-99DD-00FA-E835FEA/Library/NoCloud/
The hash in the middle is renewed on every install, so the stored full paths in DB are not valid anymore.
Solution
If you still can do it (no deploy yet, no real users), store only the relative path and complete it every time with this.file.dataDirectory (or wherever you wanted to store your files).
If you already have real users and want your update to 'find the files', just ignore the first part of the stored path and build it like before:
const ValidUri = this.file.dataDirectory + // The injected cordova-plugin-file
'relativeSubDirectories/' + // If you store your files in some subdirectory
this.document.storedFullPath.substr( // Take from fullPath only the filename
this.document.storedFullPath.lastIndexOf('/') + 1
);
Where storedFullPath is the string file:///var/mobile/....
After that, you still have to do the webView conversion and the sanitizing, like in the question above.
Hope this helps someone.

Localize iOS App name in Unity

I'm'developing a Unity3D game that shows a different (localized) app name in the iPhone's home screen according to the user local language. Note that:
I already know how to localize the iOS app name by editing the Xcode project (create a InfoPlist.string file, localize it, add the CFBundleDisplayName key to it, etc.)
I also know how automatically localize an Android app name within the Unity editor (add a values-XX.xml file with the app_name property onto Assets/Plugins/Android/res/ folder, etc.)
The question is: how can I automatically localize my iOS app name within the Unity Editor so that I don't need to perform the error-prone task 1. every time I build the project?
I think that PostprocessBuildPlayer should be the way to go, however I haven't found any documentation on how to parse it and/or modify the Xcode project file correctly to achieve this.
Long time ago I ran into trouble when I tried to modify info.plist via the Build Player Pipeline especially when doing it in Append mode. It works only once and then subsequent builds fail with "The data couldn’t be read because it isn’t in the correct format." (s. Unity forum posts like this one and my blog posting about this problem) So I decided to take the alternative way combining a customised build with an Xcode Build Pre-action.
Three steps are required:
(1) Xcode setup:
In Xcode go to Edit Scheme / Build / Pre-actions. Then click the + sign to add a New Run Script Action.
In Provide build settings select Unity-iPhone.
Paste . ${PROJECT_DIR}/modify_info_plist.sh (note the dot and blank at the beginning, is ensures that the script is executed in the caller's shell)
So it should look like this:
(2) Script modify_info_plist.sh:
Within your script you have access to all environmet variables from Xcode (s. Xcode Build Setting Reference) and you can manipulate Info.plist using the defaults command (man page). Here is a sample I used to add gyroscope to the UIRequiredDeviceCapabilities:
# Code snippet used in Unity-iPhone scheme as "Build Pre-Action"
my_domain=${PROJECT_DIR}/Info.plist
status_bar_key=UIViewControllerBasedStatusBarAppearance
logger "Start adding keys to info.plist"
defaults write $my_domain $status_bar_key -boolean NO
if [ `defaults read $my_domain UIRequiredDeviceCapabilities | grep "gyroscope" | wc -l` = "0" ]; then
defaults write $my_domain UIRequiredDeviceCapabilities -array-add "gyroscope"
fi
logger "Keys added to info.plist successfully"
(3) Build Pipeline:
Put the following code in a static editor class to create a new menu item Tools / My iOS Build with shortcut cmd+alt+b:
static string IOSBuildDir= "Develop";
[MenuItem("Tools/My iOS Build %&b")]
public static void IOSBuild () {
string[] levels = { "Assets/Scenes/Boot.unity",
"Assets/Scenes/Level-1.unity",
// ...
"Assets/Scenes/Menu.unity"
};
string path = Directory.GetCurrentDirectory ();
path += "/" + IOSBuildDir + "/Info.plist";
if (File.Exists (path)) {
Debug.Log ("Removing file " + path);
File.Delete (path);
}
BuildPipeline.BuildPlayer (levels, "Develop", BuildTarget.iPhone,
BuildOptions.AcceptExternalModificationsToPlayer);
}
I know this is no perfect solution but it's the only one I found to work stable. Two drawbacks:
Step (1) has to be repeated after major Xcode format changes
New scenes have to be appended in the editor class code in step (3)

Fuse File System- general input/output error while accessing office files

I have written a fuse mirror file system using FUSE-JNA, Which mirror local directory.
This Mirror file system allow me to open all types of files correctly with no issue but it does not open all types of office files e.g. .docs , .xls etc. And give me be below error while opening any office file.
Note:
I thought its LibreOffice issue, so I removed it and installed OpenOffice. But get the same issue.
Secondly, the errors only pops up when I try to access an office file from my MirrorFileSystem. Office files opens correctly if accessed normally via ubuntu default file system.
So its some thing wrong with my File system.
Finally, (i don't know whether its related to the question or not but) in my mirror file system when I Right Click on a file>Properties> Permission its shows all the fields disabled, as below
This is my getatt() method:
public int getattr(final String path, final StatWrapper stat)
{
....
if (f.isFile())
{
stat.setMode(NodeType.FILE,true,true,true,true,true,true,true,true,true);
stat.size(f.length());
stat.atime(f.lastModified()/ 1000L);
stat.mtime(0);
stat.nlink(1);
stat.uid(0);
stat.gid(0);
stat.blocks((int) ((f.length() + 511L) / 512L));
return 0;
}
...
}
Please guide me how to fix general input/output error while office files?
Office files are not special. There is some other problem with your filesystem implementation, and you need to do more debugging work to find out precisely what the trigger and the cause is. It's very unlikely that the trigger truly is "the file is an office file", unless you have stuff in your filesystem code that operates differently based on the type of file it's dealing with (in which case you should look there). As a first debugging step, you could compare the sha1sum and stat output of the files from the fuse filesystem and from the root filesystem to see if they match. If they don't, adjust the filesystem code such that they do. You could also enable logging on your filesystem class and check if it's returning an I/O error code anywhere. The error message "general input/output error" makes it sound like that is the case.
As for the reason the permissions fields are disabled, that's because the file is owned by root, and you are not root so you can't change the permissions. The reason the file is owned by root is because you set stat.uid(0); and stat.gid(0); in getattr. UID 0 and GID 0 are for the root user and root group respectively. Fuse-JNA already puts the current UID and GID as default stat attributes in getattr, so if you want to use these then just don't call stat.uid(0); or stat.gid(0);.
Thanks for the answer.
I searched on web, on many websites they showed file locking as the reason e.g. https://forum.openoffice.org/en/forum/viewtopic.php?f=10&t=2020 etc
So in fuse, I implemented file lock function and simply return 0
My problem solved. Now I can open all types of office files.
But I do not know, is it perfect solution

error in creating a media folder using Media.makeNew

I've upgraded my umbraco to 4.7.1.1
when I create a new content item, I write it in my db and I have a task that calls a web-service that creates
a media folder accordingly
this works well from the WS in my computer (with the production DB),
but when i run the WS from the production server I get this error on media.createNew(name, new MediaType(1031), new User(0), parentId):
node: Could not find a IDataType control matching DataEditorId cccd4ae9-f399-4ed2-8038-2e88d19e810c in the controls collection. To correct this, check the data type definition in the developer section or ensure that the package/control is installed correctly.====== at umbraco.cms.businesslogic.datatype.controls.Factory.GetNewObject(Guid DataEditorId) at umbraco.cms.businesslogic.property.Property.MakeNew(PropertyType pt, Content c, Guid versionId) at umbraco.cms.businesslogic.Content.createNewVersion() at umbraco.cms.businesslogic.Content.CreateContent(ContentType ct) at umbraco.cms.businesslogic.media.Media.MakeNew(String Name, MediaType dct, User u, Int32 ParentId) at Netcraft.Utilities.Common.MediaHandler.CreateNode(String name, Int32 parentId, Int32 contentId) in C:..\Common\MediaHandler.cs:line 29 at Netcraft.Utilities.Common.MediaHandler.CreateMediaFolder(Document document) in C:..\Common\MediaHandler.cs:line 79 at Netcraft.WebService.EventManagerService.Execute() in C:..\EventManagerService.asmx.cs:line 75==============
the dlls and configs are identical, I understand he's looking for the folder control.. what is the problem?
when the code is finished, a new folder is created but when i click it i get :
Value cannot be null.
Parameter name: Property contents (27) on Content Type Folder could not be retrieved for Document 21741 on Tab Page Contents. To fix this problem, delete the property and recreate it.
Update:
I looked up the control id (cccd4ae9-f399-4ed2-8038-2e88d19e810c),
it's MediaFolder which sounds like a standard control(?)
where should i check if it's installed?
I'm capable of creating a media folder manually
and the test from my local environment (a webservice on my computer pointing to the prod DB) , created a media folder on the production env..
what does this mean?
I'm an umbraco newbie :)
thanks!
Igal
figured it out..
the webservice i was using , had an application pool that didn't have permissions on the media folder.
that fixed it!

Team Foundation Build Activitie "DownloadFiles" is giving error

I am customizing the default build process template in TFS 2010.
i am using "DownloadFiles" build activity and in server path i have given "$/TFS/Libraries/Foo.DLL", when i run the execute definition its throwing error as "Access to the path '\ServerName\SharedFolder\BuildName\TempFolder' is denied.".
But when i give server path as "$/TFS/Libraries" its downloading all the files in Libraries folder into shared TempFolder.
But i need do download only one file. Please help..
Thanks in advance..
Now, DownloadFiles does work for a whole folder only:
ServerPath="$/proj/path" - works great, all is downloaded to LocalPath.
ServerPath="$/proj/path/name.ext" - borked.
I've de-compiled DownloadFiles to see why: First it gets a list of server items, in our case just $/proj/path/name.ext. Then, it calculates the local path like this:
localItemPath = Path.Combine(LocalPath,VersionControlPath.MakeRelative(ServerItem, ServerPath));
In this line, the activity assumes that ServerPath is a path. If it's not, then MakeRelative will not recognize it, and the local path will be LocalPath/$/proj/path/name.ext, as the OP has observed.
Also, if ServerPath is not canonical - for example, $/proj/path/../path2, the same will happen. Solution: use VersionControlPath.GetFullPath(myNonCanonicalPath).
You need to grant the user running the build service with write permissions on the shared folder.
http://msdn.microsoft.com/en-us/library/cc668757.aspx
There are two separate Build activities, DownloadFiles for a folder ServerItem and a DownloadFile for a single file ServerItem.I'd expect it should work with DownloadFile.

Resources