I have been using Illustrators API to create a script that is able to export .ai files swatches into a JSON format.
This however is all by having to open the Illustrator file and click
File > Scripts > Run My Script.
This is something that is very tedious and was wondering if there was a way in order to take the the files location (file path) and just execute the program using something like Node which will just use my already existing code and my AI file.
Currently I have something that looks along the lines of:
var Exporter = function() {
this.swatchGroup = 'ClientColours';
this.myApp = app.activeDocument;
this.chosenSwatchGroup();
this.writeFile(); };
What I am thinking is there not a way to instead of having this.myApp = app.activeDocument; to rather have something like this.myApp = Path(../my location);?
I have been making us of this documentation Jongware and Adobe Documentation just cant seem to find the answer I am looking for in order to get closer to this sort of automation.
EDIT
Did some digging and found the application documentation and there is a 'path' property just not sure on its implementation. Documentation
Yes, you can do this by providing path. But you have to open that file and that file will be your activeDocument. For eg :
var file = File("../your location");
app.open(file);
this.myApp = app.activeDocument;
By this, the file at your location will get open in Illustrator and will be activeDocument.
Related
I am working with Angular 5, I have an application in which I need to read an AMP HTML file as text. This file is contained in a component and should only be accessed from this component.
I would like to be able to open the file in read-only by giving its name.
I'm actually searching for something like this:
let file = open('amp.html');
Is it possible? If not how can I do to achieve this?
If you're writing browserside JS
You can't just simply read a file. The JS is running on your browser, and you need to think about where you're getting that file from.
If the file is on a server, you need to fetch that file from the server first by making a request for it.
If you're reading a file on the user's computer, you're gonna be using the File API on the browser to allow the user to select that file.
If you're writing backend JS
Assuming you're using NodeJS, you can conduct file operations like you would with other programming languages. Check out the fs module
If i understand you correct, you can read it as text like this:
function readFile(file){
var raw = new XMLHttpRequest(); // create a request
raw.open("GET", file, false); // open file
raw.onreadystatechange = function (){ // file is ready to read
if(raw.readyState === 4){
if(raw.status === 200 || raw.status == 0){
var allText = raw.responseText;
alert(allText); // can be also console.logged, of course.
}
}
}
raw.send(null); // return control
}
usage:
readFile('link.html')
I solved this issue thankfully to this question.
I have a program where a camera is set up to constantly take pictures (about every 10 seconds or so) and the picture is sent to a folder on my server and then another program refreshes that folder constantly so that I always just have the most recent picture in that particular folder.
An HTML document exists that also constantly refreshes, and references that picture location to get and display the newest image.
What I'm trying to do is extract the EXIF data (that I've verified exists when I save the image from the active webpage and look at it's properties). I want to display the DateCreated (I believe this is DateTime) and the Latitude and Longitude (I believe is GPSLatitude and GPSLongitude).
I came across this library, exif-js, which seems like the go-to for most people trying to do this same thing in JavaScript. My code looks the same as the code at the bottom of the README.md file, except I changed out my img id="...." and variable names, (see below). It seems like it should work, but it's not producing any data. My empty span element just stays empty.
Is there an issue with the short time span that the page has before refreshing?
Thanks for any help!
Here's what my code currently looks like (just trying to get the DateTime info). I have also tried the GPSLatitude and GPSLongitude tags.
<!-- Library to extract EXIF data -->
<script src="vendors/exif-js/exif-js"></script>
<script type="text/javascript">
window.onload=getExif;
function getExif()
{
var img1 = document.getElementById("img1");
EXIF.getData(img1, function() {
var time = EXIF.getTag(this, "DateTime");
var img1Time = document.getElementById("img1Time");
img1Time.innerHTML = `${time}`;
});
var img2 = document.getElementById("img2");
EXIF.getData(img2, function() {
var allMetaData = EXIF.getALLTags(this);
var allMetaDataSpan = document.getElementById("Img2Time");
allMetaDataSpan.innerHTML = JSON.stringify(allMetaData, null, "\t");
});
}
</script>
go into ur exif.js file and then go to line 930 and then change it to
EXIF.getData = function(img, callback) {
if ((self.Image && img instanceof self.Image
|| self.HTMLImageElement && img instanceof self.HTMLImageElement)
&& !img.complete)
return false;
I know this may be already solved but I'd like to offer an alternative solution, for the people stumbling upon this question.
I'm a developer of a new library exifr you might want to try. It's maintained, actively developed library with focus on performance and works in both nodejs and browser.
async function getExif() {
let output = await exifr.parse(imgBuffer)
console.log('latitude', output.latitude) // converted by the library
console.log('longitude', output.longitude) // converted by the library
console.log('GPSLatitude', output.GPSLatitude) // raw value
console.log('GPSLongitude', output.GPSLongitude) // raw value
console.log('GPSDateStamp', output.GPSDateStamp)
console.log('DateTimeOriginal', output.DateTimeOriginal)
console.log('DateTimeDigitized', output.DateTimeDigitized)
console.log('ModifyDate', output.ModifyDate)
}
You can also try out the library's playground and experiment with images and their output, or check out the repository and docs.
I have a J2EE application where I need to implement internationalization ( I'm not using any frameworks, it's kind of a legacy application).
My Java code currently is something like this:
public String getString(Locale locale, String key){
ResourceBundle bundle
= ResourceBundle.getBundle("com.mycode.labels", locale);
return bundle.getString(key);
}
As you can see the resource files are in the java class path, so that i can use the class path for the getBundle's argument.
But now, I want to use the same resource bundle from javascript. I figured I could use the JQuery.i18n.properties plugin like this:
First we initialize it like :
var lang = 'en'; // which can be en_US or anything, should be dynamic
jQuery.i18n.properties({
name:'labels',
path:'Bundle/',
mode:'map',
language: lang
});
Then use a global function like ( for the example, otherwise i'd use it within my own libs, it shouldn't matter here.) :
function geti18nString(key){
return jQuery.i18n.prop(key);
}
This works fine if i keep a copy of the same property files i kept in my class path again in the folder where jsps are [ files may be like labels.properties, labels_en_US, and so on)
Is there a way we can use a single copy of the property files kept in just one place?
ie, if we kept it in the class path, it should be available over the url for the jquery plugin to use it ( ie, not just one file, it is picked up with different locales given to the 'language')
if we kept it in the web folder ( where the jsps are ), ResourseBundle.getBundle() should be able to pick it up from there.
I think we can use some code like :
String filePath = getServletContext().getRealPath("Bundle/");
File file = new File(filePath);
URL[] urls = {file.toURI().toURL()};
ClassLoader loader = new URLClassLoader(urls);
ResourceBundle rb = ResourceBundle.getBundle("labels", Locale.getDefault(), loader);
... if the code is written in a servlet. But that's not always the case here.
It would be great if you could guide me in the right path. Probably I'm doing something wrong.
I am having trouble writing to a file in Titanium Studio.
specifically .json file. Code is compiled through and no exception was thrown.
Here is my relevant section of code, I parse the file to var first before adding element and stringify it to be written back.
Reading works perfectly, so is adding element, it's the writing process that has issues
var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'data.json');
var jsontext = file.read().toString();
var jsondoc = JSON.parse(jsontext);
jsondoc['feedlist'].push({
"picloc":imagename,
"title":titlef.value,
"desc1":descf1.value,
"desc2":descf2.value,
"desc3":descf3.value
});
jsontext = JSON.stringify(jsondoc);
file.write(jsontext); // write(data,[append])
Note: I have consulted Documentation and done some of my own search, some are suggesting that "Filestream" should be used in place of normal file along with .close(), I have yet got them working but it could be pointers the solution, if anyone knows how to get it working
Thanks in advance.
EDIT: This question is flagged for duplication, initially I deemed that was 2 separate issues, one was about merely writing text to a file. Another is parsing event.media (picture) into a file.
I got it working now, The issue was that I was trying to write to file in read-only directory
Ti.Filesystem.resourcesDirectory: A read-only directory where your application resources are located
Ti.Filesystem.applicationDataDirectory: A read/write directory accessible by your app. Place your application-specific files in this directory.
The contents of this directory persist
until you remove the files or until the user uninstalls the application
Here is my code, directory is modified
var sesfile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'data2.json');
var jsontext = sesfile.read().toString();
var jsondoc = JSON.parse(jsontext);
jsondoc['feedlist'].push({
"picloc":imagename,
"title":titlef.value,
"desc1":descf1.value,
"desc2":descf2.value,
"desc3":descf3.value
});
jsontext = JSON.stringify(jsondoc);
sesfile.write(jsontext,false);
If you are unable to locate data directory and simply want to load the file from there.
(In my case it does not exist in project nor will be created with Webpreview compilings)
You can do bootstrap-ish type instruction like this first
var rdfile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,'data.json');
var sesfile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'data2.json');
var jsontext = rdfile.read().toString();
var jsondoc = JSON.parse(jsontext);
sesfile.write(jsontext);
hope it helps whomever makes amateur mistake like I did.
I'm not particularly using Flex but I am using javascript and html and css in a adobe air application. I would like to be able to unzip and zip files. I've looked at a few libraries but none worked as I needed it to. I read somewhere that I could use Fzip library but I need to do this in javascript most preferably but the files are actionscript files. Any advice? Thanks.
You can use almost any actionscript library with html/javascript air app. Example:
Download swc file for airxzip: http://code.google.com/p/airxzip/downloads/list
Rename swc to zip and unzip it
Rename included library.swf to coltware_airxzip.swf
Include the library on your page like this:
<script src="coltware_airxzip.swf" type="application/x-shockwave-flash"></script>
This reads a zip file and writes contents to output folder on the desktop (given you have included jQuery and the AIRAliases.js file from the SDK):
var input = new air.File();
input.addEventListener(air.Event.SELECT, function(event) {
var outputDirectory = air.File.desktopDirectory.resolvePath('output');
var reader = new window.runtime.com.coltware.airxzip.ZipFileReader();
reader.open(event.currentTarget);
$.each(reader.getEntries(), function(i, entry) {
if (!entry.isDirectory()) {
var stream = new air.FileStream();
stream.open(outputDirectory.resolvePath(entry.getFilename()), air.FileMode.WRITE);
stream.writeBytes(reader.unzip(entry));
stream.close();
}
});
});
input.browseForOpen('Select a zip file...', [new air.FileFilter('Zip files', '*.zip')]);
I wrote a sample app for Adobe Air + FZip using javascript.
Figured I'd share that here in case anyone else arrives here via Google.
Can never have too many working examples right?
Example -> http://www.drybydesign.com/?p=233