Run Photoshop Script only after all files were opened - javascript

I am trying to make Photoshop tell me how many Files were opened in Photoshop.
Of course I can always go and check in finder, how mnay files I tried to open - but that is not always accurate, sometimes for unknown reason files are skipped. I could also go and count manually, although that takes very long. I've written a simple script which tells me how many file were opened.
if (!documents.length) alert("No Open documents");
else alert(documents.length + " images opened");
At the moment I simply put it into the action. I open all the files, 200 images, run the action - I receive a pop up message. It is great.
But is there a way to make it automatic? To make the script run only on the last file opened? How would I go about automating it?

Maybe you can use a script to open the files instead of Open command? The script will ask for files location as Open command normally would but in the end you can do whatever you want when files were opened.
var inputFiles = File.openDialog(undefined, undefined, true); //multiselect: true
if (inputFiles != null)
{
for (var i = 0; i < inputFiles.length; i++)
{
open(inputFiles[i]);
}
alert(documents.length);
}

Related

JS Will not refresh with caching disabled

I have tried everything I can think of including appending .js files with ?ver=blah, and the browser still loads the old version of my script.
If I pull the script .js file up in the browser directly it is still the old file.
If I download it through FTP I get the new file.
I have tried both chrome and firefox browser(I installed FireFox fresh AFTER writing the new JS file, and somehow firefox is STILL loading the old file, which it had never even been exposed to...?)
I added this code at line 30 in the latest verson:
if (lastRecipeBlockIndex == parent.children().size()) {
//find tallest column and set parent div height to match
var tallID = 0;
for (var i = 0; i < columnHeights.length; i++){
if (columnHeights[i] > columnHeights[tallID])
tallID = i;
}
parent.height(columnHeights[tallID]);
return;
}
Line 31 used to be a return statement.
Url to this file: http://tmurraywellness.com/wp-content/plugins/TM%20Code/TM-script.js?ver=0.01j
What does anyone else see?
The server has to be sending the wrong file. Caching is impossible since I have changed the url. Caching as mentioned is disabled anyway with dev-tools open in both browsers(I manually ticked the box to make that happen)
Any suggestions? I am desperate. I have spent hours trying to get the ten lines of code below to execute in my browser(s)

javascript prompt select a file (no upload, just get file name)

I'm mixing javascript and imacros to automate some tasks.
The main JS file will do some stuff and go to my website in firefox. Then, the script check if the word "confirmation" is found
Here's what i have so far
var macro = "CODE:";
(...)
var big_count=parseFloat(prompt("how many loops ?",100));
for(var x=0;x<big_count;x++)
{
iimSet("rnd",Math.floor(Math.random()*2000 + 1));
iimPlay(macro);
if(window.content.document.body.textContent.contains('confirmation'))
{
//if confirmation word found
iimPlay("CODE:WAIT SECONDS=60");
}
else
{
//if confirmation word isn't found
}
}
If the confirmation word is found, i want to launch another .iim script. I know i can do this using the following:
iimPlay("myFile.iim")
But the user running the .JS file needs to be able to chose which .IIM file will be run at the end of the script. How can i do this ?
I need some sort of prompt dialog that will list all files inside the following folder:
C:\Users\Libertad\Documents\iMacros\Macros
Then when a file is selected, pass the file name to the iimPlay() function

Get Element available under Dev Tools -> Resources -> Frames

I'm trying to do this by using a Tampermonkey Script. However I'm open to new approaches...
What I want to do is extract some data (data-video), from a specific <div>. However this data is not available under the HTML code of the page, but it's available under Dev Tools -> Resources and then on Frames.
Anyone knows if it's possible to get that information available under DevTools? And how can I do that?
Comparative between the two pages can be found here: "Original HTML PAGE" and "HTML PAGE under DevTools"
On the first hyperlink the id=video-canvas cannot be seen, however it's on the <object type="application/x-shockwave-flash(...)
As you state in your question the data you're looking for is available in DevTools under the "Resources" tab in the "Frames" folder. What you are looking at there is the Source HTML, similar to View Source.
The code you want, is what is getting replaced. It appears the site is using the JW Player Plugin, which is replacing the <div id="video-canvas"> with the appropriate HTML for the device / browser detected to play the video. With all of my browsers on my Mac, they are being forced to use the Flash, even when it's disabled. When using my iPhone, which can't play flash , and inspecting the page it uses JW's own custom video element. It appears that it must be storing the file location in memory since it is not in the generated markup.
I am able to run through the console in the dev tools and access their JS class. It appears i can call jwplayer._tracker , which has an object b . Object b has an object AlWv3iHmEeOzwBIxOUCPzg This object seems to be consistent each time i check between different browsers, you can use the for loop inmy first example to get the correct value but tirmming it down to .b Following that object is e and in e is the object http://i.n.jwpltx.com/v1.... really long string that appears to contain a url, so it will need to parsed.
So to get the HTML string i ran
for ( var loc in jwplayer._tracker.b.AlWv3iHmEeOzwBIxOUCPzg.e){
loc
}
so if we put that in a function to parse the string and return a value
function getSubURL(){
var initURL;
for ( var loc in jwplayer._tracker.b.AlWv3iHmEeOzwBIxOUCPzg.e){
initURL = loc;
}
//look for 'mp4:' this is in front of the file path
var start = initURL.indexOf("mp4%3A");
//look for the .mp4 for the end of the file name
var stop = initURL.indexOf(".mp4");
//grab the string between
//start+6 to remove characters used to find it
//and stop+4 to include characters used to find it
var subPath = (initURL.substring((start+6),(stop+4))).split("%2F").join("/");
return subPath;
}
//and run it
getSubURL();
it will return ciencia/astronomia/fimsol.mp4
you can run this from your console, but I am unaware of how you can use this in Tamper Monkey, but i think it gets ya a lot closer to what you wanted.
This is the approach I've used to solve my problem... I couldn't grab the code I want under Dev Tools, but I find a way to get the data from jwplayer with the function getPlaylistItem. And this is how I get the url filename of each video:
function getFilename(filename) {
var filename;
if(jwplayer().getPlaylistItem){
filename = jwplayer().getPlaylistItem()['file'];
}
else{
return filename;
}
filename = filename.substring(filename.indexOf("/mp4:") + 5);
return filename;
}

Inject local .js file into a webpage?

I'd like to inject a couple of local .js files into a webpage. I just mean client side, as in within my browser, I don't need anybody else accessing the page to be able to see it. I just need to take a .js file, and then make it so it's as if that file had been included in the page's html via a <script> tag all along.
It's okay if it takes a second after the page has loaded for the stuff in the local files to be available.
It's okay if I have to be at the computer to do this "by hand" with a console or something.
I've been trying to do this for two days, I've tried Greasemonkey, I've tried manually loading files using a JavaScript console. It amazes me that there isn't (apparently) an established way to do this, it seems like such a simple thing to want to do. I guess simple isn't the same thing as common, though.
If it helps, the reason why I want to do this is to run a chatbot on a JS-based chat client. Some of the bot's code is mixed into the pre-existing chat code -- for that, I have Fiddler intercepting requests to .../chat.js and replacing it with a local file. But I have two .js files which are "independant" of anything on the page itself. There aren't any .js files requested by the page that I can substitute them for, so I can't use Fiddler.
Since your already using a fiddler script, you can do something like this in the OnBeforeResponse(oSession: Session) function
if ( oSession.oResponse.headers.ExistsAndContains("Content-Type", "html") &&
oSession.hostname.Contains("MY.TargetSite.com") ) {
oSession.oResponse.headers.Add("DEBUG1_WE_EDITED_THIS", "HERE");
// Remove any compression or chunking
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
// Find the end of the HEAD script, so you can inject script block there.
var oRegEx = oRegEx = /(<\/head>)/gi
// replace the head-close tag with new-script + head-close
oBody = oBody.replace(oRegEx, "<script type='text/javascript'>console.log('We injected it');</script></head>");
// Set the response body to the changed body string
oSession.utilSetResponseBody(oBody);
}
Working example for www.html5rocks.com :
if ( oSession.oResponse.headers.ExistsAndContains("Content-Type", "html") &&
oSession.hostname.Contains("html5rocks") ) { //goto html5rocks.com
oSession.oResponse.headers.Add("DEBUG1_WE_EDITED_THIS", "HERE");
oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);
var oRegEx = oRegEx = /(<\/head>)/gi
oBody = oBody.replace(oRegEx, "<script type='text/javascript'>alert('We injected it')</script></head>");
oSession.utilSetResponseBody(oBody);
}
Note, you have to turn streaming off in fiddler : http://www.fiddler2.com/fiddler/help/streaming.asp and I assume you would need to decode HTTPS : http://www.fiddler2.com/fiddler/help/httpsdecryption.asp
I have been using fiddler script less and less, in favor of fiddler .Net Extensions - http://fiddler2.com/fiddler/dev/IFiddlerExtension.asp
If you are using Chrome then check out dotjs.
It will do exactly what you want!
How about just using jquery's jQuery.getScript() method?
http://api.jquery.com/jQuery.getScript/
save the normal html pages to the file system, add the js files manually by hand, and then use fiddler to intercept those calls so you get your version of the html file

Valums file uploader: how to start with ID other than 0?

I'm using Andrew Valums' Ajax Upload plugin (GitHub link). Here is some code from it:
qq.getUniqueId = (function(){
var id = 0;
return function(){ return id++; };
})();
It's kind of a long story, but I'm in a situation where, under certain circumstances, I'd like the qq.getUniqueId function to start with an ID other than 0. It can still increment by one; it just has to start with something other than 0. What's the best way to do that?
Here are the steps to create a test environment:
Download the plugin: http://github.com/valums/file-uploader/zipball/master
Unzip it and move the "client" folder onto a web server.
Open the "demo.htm" file in a text editor, search for action: 'do-nothing.htm', and add onComplete: function(id, fileName, responseJSON) {alert(id)}, right after that.
Open the "demo.htm" file in a web browser. Be sure to access it through a web server (as opposed to just opening the local file) or else it won't work.
Upload a file. It should alert a "0" after the upload finishes. See if you can modify it so that I can pass in a different starting number.
Thanks!
Try replacing the function with one that calls the original, but adds an offset:
function offsetUniqueId(n) {
var old = qq.getUniqueId;
qq.getUniqueId = function() {
return old() + n;
}
}
See http://jsfiddle.net/alnitak/gWjqX/

Categories