Executing .exec file using Objective-C Code - objective-c

I am trying to make some edits on RWTS-PDFWriter Source Code:
https://github.com/3gx/RWTS-PDFwriter
To make it execute an exec file when it saves the pdf to make some changes on it. but when I hit print it always shows me that there is a backend error.
I am not very good at Objective-C, I need this project for my university assignment.
I added the code block to the pdfwriter.m file.
#autoreleasepool {
[[NSTask launchedTaskWithLaunchPath:#"/private/var/spool/spaceprinter/QrMake.py"
arguments:#[#"/Users/philipnakhleh/Desktop/pos.pdf"]]
waitUntilExit];
}
but it show me backend error when I print. But, when I run the same code on a separate project it runs without problems.
Any Help??

I solved it without using code.
I made a .plist file and put it in the ~/Library/LaunchAgents.
Whenever a file added to the directory the exec file will trigger and do the processing.
PS: if you want to do it for all users put it in /Library/LaunchAgents.

Related

Running extendscript (.jsx) launches ExtendscriptToolkit

I have written a couple of simple .JSX scripts that automate some common monkeywork I do in Photoshop.
I wrote the scripts in ExtendScriptToolkit and then execute them with File > Scripts > Browse and select the script I want. This runs the script and does what I want it to but it also launches ExtendScriptToolkit again each time. I have passed the script to a few others at work and they have all asked me to fix this so that the script executes purely within Photoshop but I can't make it work.
Basically, how can I run the script from Photoshop without it launching the script editor as well?
Cheers in advance for your help
Check your script for $.writeln() statements. This could be a problem. You can also suppress debugging by setting the debug level.
Taken from the Object Model Viewer in ESTK
// $.level  
// Data Type: number
// Core JavaScript Classes
// The current debugging level, which enables or disables the JavaScript debugger.
// One of 0 (no debugging), 1 (break on runtime errors), or 2 (full debug mode).
$.level = 0;
$.writeln("something");
alert("Hello World");
Edit:
I tried the debug level with the script above. It still opens the ESTK :-(
Looks like it does not work. Can anybody confirm this?
$.level = 0;
"The current debugging level, which enables or disables the JavaScript
debugger. Read only." Page 217
But when script run from ESTK $.level == 1
When from APP $.level == 0
Аnd solution may be if ($.level) $.writeln("JSC");

Compile time check for valid file references in Xcode

Is it possible to force the Xcode complier to verify that files referenced in code are valid?
There are multiple points in Cocoa development when you naturally reference a file programmatically via an NSString:
[UINib nibWithNibName:#"MyNib" bundle:nil];
[UIImage imageNamed:#"MyImage"];
[[UIViewController alloc] initWithNibName:#"MyNib" bundle:nil];
Is there any way at compile time to check is these file references are valid?
Often times after using above methods, I end up changing the name of the referenced file but forget to change the name in code. Everything complies without a problem and it is only when you happen to go to the portion of the app that accesses this file that the bug will reveal itself.
Is there another approach or technique that people use to avoid this sort of error?
Referencing a file name via a string feels very fragile.
Warning: This answer is mostly outdated. The general idea is fine but better solutions exist now (e.g. Image assets with a SwiftGen script to generate an enum).
Nibs usually have a class with the same name as the file, e.g.
[[MyViewController alloc] initWithNibName:NSStringFromClassName([MyViewController class]) bundle:nil];
I usually hide it into the controller's init method as [self class].
For image loading, compile-time checks are difficult. Help yourself with macros, first replace the loading method by a simple macro, e.g.
#define LOAD_IMAGE(__IMAGE_NAME__) [UIImage imageNamed:__IMAGE_NAME__]
First thing you should do is to put an assert into this macro and always check that the image was successfully loaded. It's not a compile-time check but it helps to find missing resources.
The second thing is to write a ruby/python/shell/(any scripting language) script that will search your source files for LOAD_IMAGE and check if the file (between parenthesis) exists. As a shell script, it will be very simple (e.g. using grep). You can add this script into your xcode project to be run when compiling.
Don't forget to check images referenced by xibs.
However, often you have to create the image name dynamically, e.g. NSString* imageName = [NSString stringWithFormat:#"image_%i", index]. There's no way how you can check this at compile time.
Also don't forget to do the reverse check - don't include image files which are not used anywhere.
AutoComplete for [UIImage imageNamed:] by Kent Sutherland.
This provides code completion support within Xcode - a brilliant piece of code. This is working for me in Xcode 4.6:
Currently this project does not have support for strings other than imageNamed:. To support those, I will try to write a compile time script. Or maybe I will become bold and try to extend Mr. Sutherland's spectacular work.
Xcode doesn't support this, but if this problem is really biting you then you could use the following hack:
Give every in-bundle file a unique prefix (e.g. app__)
When you add a file to your project, make sure you first rename it to add this prefix.
Your compile time (pre-distribution) check then has two parts: 1) Search through all .m files and enumerate strings that begin with the prefix. You shouldn't have to check if the string is quoted since your prefix is unique. 2) grep project.pbxproj for each string to check if it is included in the bundle.
With some effort, this process can be mostly automated and also optimized, but the above recipe ought to work.
here is a bash script that we use that lists all images on disk but NOT referenced in code.
https://gist.github.com/3750087
it would likely be easy to reverse this to check for non-exting images and xibs.
Anyways, the script should be a good starting point

Error 256 Reading via NSString's initWithContentsOfFile

I am attempting to read a number of files from a directory tree inside the Documents directory within my App andbox.
Most of them are xml files which I read with :
NSData *data = [NSData dataWithContentsOfFile:packagefile.
RXMLElement *rxml = [RXMLElement elementFromXMLData:data];
All but one them read OK. But one does not read and I get error code 256.
For the bad file I can also try :
NSData *data = [NSData dataWithContentsOfFile:packagefile options:0 error:&err];
but the same error code comes back . (Hence I think my issue is not related to the actual xml content of the file).
Clearing out the sandbox and copying all the files back in programatically in my App makes no difference.
What can be wrong here? What else can I do?
I have found a solution to this problem ('inexplicable error code 256'.) Hopefully this solution will be helpful to other developers who hit this issue.
It had run out of file handles.
In my App I had a also logging function which logged activity to file (a bit like Log4J). This took each logged statement – opened a file using a 'NSFileHandle' followed by 'seekToEndOfFile' followed by 'writeData'.
I was relying mistakenly upon the ARC disposing and closing the file on exit from the logging procedure. Clearly ARC does not close the file and eventually the system runs out of file handles.
The solution is simply to call 'closeFile' as one would in Java or C.

Array Doesn't load PNGs Exported from After Effects: ios, xcode

Our graphic designer is sending us .PNGs named appropiately "hide_00~iphone.png", "hide_00#2X~iphone.png" etc
He is exporting the images from after effects. I add them to the project and try to load them into an array on init. An exception is thrown each time for all of his files. Now, if I go in AND RENAME the files in the finder to exactly the same name, everything compiles fine. I have no idea what's going on here. Xcode cannot find them in the file system until I rename them. But the name is EXACTLY the same as what he sent me. I checked for white space around his file naming but everything looks fine.
Does anybody know if After Effects puts weird header info in the images? Or does this sound familiar at all to anyone. There are a whole bunch of images we are working with and I would hate to have to rename them by hand.
So I just used imageNamed and the image loaded just fine. So obviously your routine to load the image by path/name is flawed. You can post that and it can be evaluated - but this has nothing to do with 'After Effects'.
EDIT: For the record, my system is Lion Xcode 4.4.1 and my project set for iOS 5.1. I took your file from dropbox, and verified that in my project I CAN load the image as you are trying to do:
for (int i = 6; i < 7; i++) {
NSString *path = [NSString stringWithFormat:#"hide_step_seq_%02d", i];
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:path ofType:#"png"]];
NSLog(#"PATH %# image=%#", path, image);
}
2012-09-13 07:15:23.241 Searcher[58114:f803] PATH hide_step_seq_06 image=<UIImage: 0x6a4cb30>
So, where to go from here? I've tried to help several people here who get burned by the #2x or ~iphone suffixes. For some reason a few people cannot ever seem to get this to work - all I can think of is there is some flag deep in the system that gets toggled and there is no way to untoggle it.
My suggestion is to try using the actual complete file name - try appending ~iphone and see if that works.
You can also in Terminal do a 'ls *.png | od -c' before changing the name and afterwards, to verify that absolutely the characters are the same.
The last thought I have on this is that files have many attributes: creation time, last access, last modiied, extended attributes, permissions, etc. It is possible (while unlikely) that for some reason one of these values blocks the system from attempting to use the ~iphone suffix.
I really wish I could help you further. If you want to put a simple little project together that does nothing more than tries to open a few images and it fails, zip the whole project up, put on dropbox, I'd be more than willing to run it on my system to try and duplicate the problem. You can also do as I did in the code above and verify that path looks good and the image is nil.

How can I work around "Xcode could not locate source file"

I'm working with the ID3 framework in Xcode (which has since disappeared off the face of the web - including google cache!).
I'm testing out an import mp3 feature which allows them to edit the tags as they import them. One of the test cases is a corrupt or invalid mp3 with no proper id3 header. The problem I'm having is that when updating the tags of the invalid mp3 (updateFile:), the ID3 framework attempts to use id3V1Tag.m (I assume it falls back to this if it can't find the v2 tag) and this is where I get the Xcode error (whilst running the program, not building):
Xcode could not locate source file: id3V1Tag.m (line: 299)
Even in a release build this crashes the program, so it's not something I can really ignore.
I've tried putting a try/catch block around it but it's not treated as an exception so doesn't get caught. The function to load the tag data for the file returns a BOOL but it appears this only returns false if the given file doesn't exist, so this doesn't help either.
Current code:
[tagData release];
tagData = [[TagAPI alloc] initWithGenreList:nil];
tagsLoaded = [tagData examineFile:exportPath];
if(tagsLoaded) {
[tagData setTitle:title];
[tagData setArtist:artist];
[tagData setComments:comments];
#try {
[tagData updateFile];
}
#catch (id e){
NSLog(#"h");
}
}
The error you're getting is that Xcode is trying to locate your source file id3V1Tag.m in order to show it during debugging. No code you write will affect this.
If you don't have the id3V1Tag.m source file in your framework distro, there's nothing you can do about this, and there's little to do but ignore it (other than seeing if you can avoid causing it to be requested, like not setting a breakpoint in it, not stepping into it, and not crashing in it).
If you do have it, and are building it, then perhaps you're not building with the right debug information, so you'll have to tell us more about your build setup.
So the problem you're having is that your program is crashing when you attempt to compile id3V1Tag.m or while running the program. I'm a bit confused on that.
If its crashing while running maybe this is an issues with a code file missing from a library? How are you reading the ID3 tag information exactly? Is it through your own code or through a 3rd party library/class.