I am trying to create a small script which will read how many steps were made while editing specific image. While also checking what tools were used. And then export all the results into various categories in .csv.
I have the Output part.
I have the history states.
But how would you check if specific tool e.g.: Liquify, Clone Stamp, Free Transform etc. was used?
I have the below script. Which quickly checks if I used the tool, but if it wasn't used, it throws an error:
No such Element. Line: 13
-> var LiquifyUsed = app.activeDocument.historyStates.getByName('Liquify');
var LiquifyUsed = app.activeDocument.historyStates.getByName('Liquify');
//Check if Liquify was used
if (LiquifyUsed = true) {
alert ("Liquify was used")
} else {
alert ("It was not used")
Simply catch the exception:
var liquifyUsed = false;
try {
app.activeDocument.historyStates.getByName('Liquify');
liquifyUsed = true;
} catch(e) {
// assume the error is always "No such element" --
// you could be more fastidious and check instead.
}
alert('Liquify used: ' + liquifyUsed);
Related
I'm rather new to node.js and javascript aswell, and I keep running into an error with the code below.
fs.watch('F:/junk', (eventType, filename) => {
if(filename && filename.split('.')[1].match("zip")) {
try {
var zip = new azip(dir + filename);
} catch(err) { return console.log(err); }
try {
zip.extractAllTo(dir + filename.split('.')[0], false);
} catch(err) { return console.log(err); }
}
});
and the error. the error only occurs after successfully running extractAllTo (adm-zip), and doesn't occur at all if I take that bit out.
if(filename && filename.split('.')[1].match("zip")) {
TypeError: Cannot read property 'match' of undefined
I'm using the same file for testing every time, with the name dummyfile.zip
I can create another if statement within the first one and it'll work fine, but seems a bit redundant doing it that way
You must test for the existence of array element 2 (or index 1). There are numerous reasons. Without knowing operating system and file structure it is impossible to tell you. For instance, fs.watch() will return a directly - if the directory has no '.', then fail. This is the same if a file has no extension.
To validate this, in the console do this:
let str = "directory name";
str.split('.');
str.split('.')[1].match('test');
view the output.
Consider
if(filename && filename.includes('.zip')) {
// work
}
}
code is a little more verbose, but will avoid the error caused by directories and files that do not have extensions and files with leading dots, etc.
I am debugging a javascript/html5 web app that uses a lot of memory. Occasionally I get an error message in the console window saying
"uncaught exception: out of memory".
Is there a way for me to gracefully handle this error inside the app?
Ultimately I need to re-write parts of this to prevent this from happening in the first place.
You should calclulate size of your localStorage,
window.localStorage is full
as a solution is to try to add something
var localStorageSpace = function(){
var allStrings = '';
for(var key in window.localStorage){
if(window.localStorage.hasOwnProperty(key)){
allStrings += window.localStorage[key];
}
}
return allStrings ? 3 + ((allStrings.length*16)/(8*1024)) + ' KB' : 'Empty (0 KB)';
};
var storageIsFull = function () {
var size = localStorageSpace(); // old size
// try to add data
var er;
try {
window.localStorage.setItem("test-size", "1");
} catch(er) {}
// check if data added
var isFull = (size === localStorageSpace());
window.localStorage.removeItem("test-size");
return isFull;
}
I also got the same error message recently when working on a project having lots of JS and sending Json, but the solution which I found was to update input type="submit" attribute to input type="button". I know there are limitations of using input type="button"..> and the solution looks weird, but if your application has ajax with JS,Json data, you can give it a try. Thanks.
Faced the same problem in Firefox then later I came to know I was trying to reload a HTML page even before setting up some data into local-storage inside if loop. So you need to take care of that one and also check somewhere ID is repeating or not.
But same thing was working great in Chrome. Maybe Chrome is more Intelligent.
I've set up error logging on my windows store app, which reports the error message and the line number in the code.
I've been getting two error messages from the same line, line 301. The error messages are
The process cannot access the file because it is being used by another process.
Access is denied.
Based on the First error message I presume the error is with my autosave function, but without the line number I can't say where it's failing. Here's my autosave code
function autosave()
{
if ((localSettings.values["useAutoSave"] == null || localSettings.values["useAutoSave"] == "true")) {
editorContent = editor.textContent;
var text_length = editorContent.length;
if (editedSinceSave && text_length > 0) {
localSettings.values["lastContent"] = text_length;
setStatus("<span class='loader'></span>autosaving", 2000);
writeTempFile();
}
}
window.setTimeout(autosave, _autosave_timeout);
}
function writeTempFile()
{
try{
tempFolder.createFileAsync("tempFile.txt", Windows.Storage.CreationCollisionOption.replaceExisting)
.then(function (theFile) {
return Windows.Storage.FileIO.writeTextAsync(theFile, editor.textContent);
}).done(function () {
localSettings.values["lastPos"] = _lastStartPos;
});
}
catch (e) {
// statements to handle any exceptions
logError(e); // pass exception object to error handler
}
}
Even we I move all my functions around and recompile my code, the error is always at line 301. I suspect that the errorline I'm seeing is actually from whatever underlying js files are used to run my app, but I don't know where to access them. How the hell do I debug this?
Make sure there's not a capability that you have not declared. It doesn't look like your code is using anything special, but it's worth a try.
I am getting a javascript error "Invalid argument on Line: 2 Char: 141544 in sp.ui.rte.js" on a SharePoint development. This appears to be a known issue from google within the SharePoint js files - http://wss.boman.biz/Lists/Posts/Post.aspx?List=c0143750-7a4e-4df3-9dba-8a3651407969&ID=69
After analysing the impact I decided that rather than changing the js in the SharePoint 14 hive I want to suppress the error message for just this error. I was trying to do the following:
ClientScriptManager cs = Page.ClientScript;
//Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered("Alert"))
{
StringBuilder cstext1 = new StringBuilder();
cstext1.Append("<script type=text/javascript> window.onerror = function (msg, url, num) {return true;} </");
cstext1.Append("script>");
cs.RegisterStartupScript(this.GetType(), "Alert", cstext1.ToString());
}
The problem is this will suppress all js errors on the page not just the sp.ui.rte.js ones. Is it possible to do a string search on the URL (http://SHAREPOINT/_layouts/sp.ui.rte.js?rev=uY%2BcHuH6ine5hasQwHX1cw%3D%3D - where the only consistent value between sites will be /_layouts/sp.ui.rte.js? ) to just search and suppress this exact error?
Thanks for any help!
Use try/catch block around code in JS. If message matches something you want to ignore, just do nothing. Propagate everything else.
Your original approach with .onerror would work too if you change it to analyze message and propagate everything not matching ignored string as well.
So far this has been the most successful fix I have found and currently using:
function fixRTEBug() {
// This Fix for parentElement bug in RTE should survive Service Packs and CU's
function SubstituteRTERangeParentElement() {
var originalRTERangeParentElement = RTE.Range.prototype.parentElement;
RTE.Range.prototype.parentElement = function () {
try {
originalRTERangeParentElement();
} catch (e) { }
}
}
SubstituteRTERangeParentElement();
}
ExecuteOrDelayUntilScriptLoaded(fixRTEBug, "sp.ui.rte.js");
I've written a script that detects the referring URL from a couple of search engines and then passes this value (not the mc_u20 variable) to a server to be used somewhere. The script works like a treat except for one big problem, it simply won't track Google search results. So any result that comes from Google, simply doesn't register. Here is the script:
var mc_searchProviders = {"search_google":"google.co","search_bing":"bing.com","search_msn":"search.msn","search_yahoo":"search.yahoo","search_mywebsearch":"mywebsearch.com","search_aol":"search.aol.co", "search_baidu":"baidu.co","search_yandex":"yandex.com"};
var mc_socialNetworks = {"social_facebook":"facebook.co","social_twitter":"twitter.co","social_google":"plus.google."};
var mc_pageURL = window.location +'';
var mc_refURL = document.referrer +'';
function mc_excludeList() {
if (mc_refURL.search('some URL') != -1) {
return false; //exclude some URL
}
if (mc_refURL.search('mail.google.') != -1) {
return false; //exclude Gmail
}
if (mc_refURL.search(mc_paidSearch) != -1) {
return false; //exclude paidsearch
}
else {
mc_checkURL();
}
}
mc_excludeList();
function mc_checkURL() {
var mc_urlLists = [mc_searchProviders, mc_socialNetworks],
i,mc_u20;
for (i = 0; i < mc_urlLists.length; i++) {
for (mc_u20 in mc_urlLists[i]) {
if(!mc_urlLists[i].hasOwnProperty(mc_u20))
continue;
if (mc_refURL.search(mc_urlLists[i][mc_u20]) != -1) {
mc_trackerReport(mc_u20);
return false;
}
else if ((mc_refURL == '') && (mc_directTracking === true)){
mc_u20 = "direct_traffic";
mc_trackerReport(mc_u20);
return false;
}
}
}
}
The most annoying thing is, I have tested this on my local machine (by populating the mc_refURL with an actual google search URL and it works like a charm. I've also thought that maybe when searching through the first mc_searchProviders object it is somehow skipping the first instance, so I added a blank one. But still this doesn't work. What's even more annoying is that for every other search engine, the mc_u20 variable seems to populate with what I need.
This is driving me insane. Can anyone see what's wrong here? I might also mention that I'm signed into Google but I don't see how this would affect the script as their blogpost (in November) said they were filtering keywords not stopping the referring URL from being passed.
Right so I figured out what was going on. The first part of the script excludes your own URL (see where it says 'some URL'. Say this was set to www.example.com. In Google if I searched for say example and Google returned www.example.com as the first search result, in the referring URL it would contain www.example.com. Hence why the script was breaking, maybe someone will find this useful in future.