I had to place videos(mp4-files) in one photoshop document. I thought it would be easier to find a solution with png/jpg, and then project it on mp4. but the fact is that photoshop saving png/jpg and mp4 in different ways. Therefore, despite the fact that there is an import solution, I have difficulties with exporting mp4 by code.
I have 2 arrays of mp4 files and each mp4 from the first array needs to be overlaid on each of the second and saved by mp4. I solved the problem by uploading a video to an open photoshop file with a simple code:
function replaceContents(newFile) {
var docRef = app.open(newFile);
return docRef;
}
function importVideos(order_number) {
var doc = app.activeDocument;
var file = new File('E:/path/' + order_number + '.mp4');
// open a new document with needed video
var docTemp = replaceContents(file);
// copy opend layer with video from new doc to my main doc
var layer = docTemp.activeLayer.duplicate(doc.layerSets.getByName(color), ElementPlacement.PLACEATEND);
// close new unnecessary doc
docTemp.close(SaveOptions.DONOTSAVECHANGES);
layer.name = order_number;
return layer;
}
Here is the code for saving videos and in doExport() doc should be saved as a video.
function Saving(color) {
var array1 = app.activeDocument.layerSets.getByName('s');
var array2 = app.activeDocument.layerSets.getByName(color);
for (i = 0; i < 5; i++) {
array1.artLayers[i].visible = true;
for (j = 0; j < 5; j++) {
array2.artLayers[i].visible = true;
doExport();
array2.artLayers[i].visible = false;
}
array1.artLayers[i].visible = false;
}
}
So a new question: how to export a video from photoshop with a code with the ability to specify the file name and the save path?
P.S. if you do this through Actions, you can't enter input parameters like the name of the saved file, it seals the Action as you did it.
If you know how to create arguments for Actions, you are welcome!
I want to copy folders into a Master Folder within Google Drive. My main issue is creating a function when one column is not blank and another column is blank.
Once, a new folder is created it has to paste in the folder URL in one of the columns.
This is what I have so far:
function addData(){
var activeSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data");
var lr = activeSheet.getLastRow();
var lc = activeSheet.getLastColumn();
var sourceData = sourceSheet.getRange(1, 1, lr, lc).getValues();
for (row in sourceData) {
if (sourceData[row][0] !== "" && sourceData[row][19] !== "") {
var rowNum = parseInt(row);
//code will go here for Folder copying and renaming and getting the new folder url
activeSheet.getRange(rowNum+1,lc).setValue("Completed"); //we will eventually change Completed with the new Folder URL
}
}
}
The main idea would be to iterate files using Folder.getFiles() and folders with Folder.getFolders(). Make new folders with Folder.createFolder(name) and copy files using File.makeCopy(name, destination):
/**
* Copies all the files in a folder to another one.
*/
function copyFolderContents_(source, target) {
// Iterate files in source folder
const filesIterator = source.getFiles()
while (filesIterator.hasNext()) {
const file = filesIterator.next()
// Make a copy of the file keeping the same name
file.makeCopy(file.getName(), target)
}
}
/**
* Recursivelly copies a folder and all its subfolders with all the files
*/
function copyFolder_(toCopy, copyInto) {
// Makes the new folder (with the same name) into the `copyInto`
const newFolder = copyInto.createFolder(toCopy.getName())
// Copy the contents
copyFolderContents_(toCopy, newFolder)
// Iterate any subfolder
const foldersIterator = toCopy.getFolders()
while (foldersIterator.hasNext()) {
const folder = foldersIterator.next()
// Copy the folder and it's contents (recursive call)
copyFolder_(folder, newFolder)
}
}
/**
* Entry point to execute with the Google Apps Script UI
*/
function copyFolder() {
// Get the folders (by ID in this case)
const toCopy = DriveApp.getFolderById('')
const copyInto = DriveApp.getFolderById('')
// Call the function that copies the folder
copyFolder_(toCopy, copyInto)
}
You need to add the ids of the folder to be copied and the folder to copy it from on copyFolder().
foldersIterator and filesIterator are Google Apps Script Iterators. They have a method hasNext() that returns if there is another item, and a next() that retrieves it.
Note that copyFolder_(toCopy, copyInto) uses itself to copy its subfolders.
References
Folder.getFiles() (Google Apps Script reference)
Folder.getFolders() (Google Apps Script reference)
Folder.createFolder(name) (Google Apps Script reference)
File.makeCopy(name, destination) (Google Apps Script reference)
Iterators (Google Ads Script concepts) (same implementation as Google Apps Script)
This solution is a variation that checks to see if the file or folder has already been copied.
Useful if you have to restart the execution.
It uses includes to check if a file/folder has been copied:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
It goes only one level deep, so won't copy subfolders of subfolders.
I've added a sort using Intl.Collator because it helps me read the console output. Neither sort nor console are needed but may be useful.
references:
https://stackoverflow.com/a/54427214/16465606
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator
https://tc39.es/ecma402/#sec-collator-comparestrings
/** Use with copyFolderContents */
function copyFolder() {
const topFolderFrom = DriveApp.getFolderById(''); // enter folder ID
const topFolderTo = DriveApp.getFolderById(''); // enter folder ID
// Get the subfolder names and IDs
const ffTopFolder = topFolderFrom.getFolders();
const subfolders = [];
while (ffTopFolder.hasNext()) {
let folder = ffTopFolder.next();
let ffnameid = [];
ffnameid.push(folder.getName(), folder.getId());
subfolders.push(ffnameid);
}
subfolders.sort((a, b) => collator.compare(a[0], b[0]));
// Get target subfolder names
const folderstarget = topFolderTo.getFolders();
const listtarget = [];
while (folderstarget.hasNext()) {
let foldertarget = folderstarget.next();
let ffname = [];
ffname.push(foldertarget.getName());
listtarget.push(ffname);
}
listtarget.sort(collator.compare);
// Check if subfolder has already been created
const alreadycreated = listtarget.flat();
const stilltocreate = subfolders.filter(e => !alreadycreated.includes(e[0]));
console.log('subfolders already created:\n', alreadycreated);
console.log('subfolders still to create:\n', stilltocreate.map(e => e[0]));
// Create subfolders
for (let i = 0, len = stilltocreate.length; i < len; i++) {
topFolderTo.createFolder(stilltocreate[i][0]);
}
// Get the name and ID of subfolders in target folder (needed in case subfolders have been created)
const ffTopFolderTo = topFolderTo.getFolders();
const subfoldersTo = [];
// Get the subfolders
while (ffTopFolderTo.hasNext()) {
let folder = ffTopFolderTo.next();
let ffnameid = [];
ffnameid.push(folder.getName(), folder.getId());
subfoldersTo.push(ffnameid);
}
subfoldersTo.sort((a, b) => collator.compare(a[0], b[0]));
// Add the top level folders to arrays to copy files in top level
subfolders.push([topFolderFrom.getName(), topFolderFrom.getId()]);
subfoldersTo.push([topFolderTo.getName(), topFolderTo.getId()]);
console.log('subfolders and top folder:\n', subfolders);
console.log('subfolders and top folder (target):\n', subfoldersTo);
for (let i = 0, len = subfolders.length; i < len; i++) {
let copyFrom = DriveApp.getFolderById(subfolders[i][1]);
let indx = subfoldersTo.map(e => e[0]).indexOf(subfolders[i][0]);
let copyTo = DriveApp.getFolderById(subfoldersTo[indx][1]);
// Call the function that copies the folder
copyFolderContents_(copyFrom, copyTo);
}
}
/** Copies all the files in a folder to another one, checking for duplicates */
function copyFolderContents_(source, target) {
Logger.log('copy from: ' + source);
Logger.log('copy to: ' + target);
// Get source filenames and IDs
const files = source.getFiles();
const listsource = [];
while (files.hasNext()) {
let file = files.next();
let ssnameid = [];
ssnameid.push(file.getName(), file.getId());
listsource.push(ssnameid);
}
listsource.sort((a, b) => collator.compare(a[0], b[0]));
// Get target filenames
const filestarget = target.getFiles();
const listtarget = [];
while (filestarget.hasNext()) {
let filetarget = filestarget.next();
let ssname = [];
ssname.push(filetarget.getName());
listtarget.push(ssname);
}
listtarget.sort(collator.compare);
// Check if file has already been copied
const alreadycopied = listtarget.flat();
const stilltocopy = listsource.filter(e => !alreadycopied.includes(e[0]));
console.log('files already copied:\n', alreadycopied);
console.log('files still to copy:\n', stilltocopy.map(e => e[0]));
// Copy files still to copy
for (let i = 0, len = stilltocopy.length; i < len; i++) {
let fileid = stilltocopy[i][1];
let ss = DriveApp.getFileById(fileid);
Logger.log(i + ' - ' + ss);
ss.makeCopy(stilltocopy[i][0], target);
}
}
/** Used for sorting alpha/numeric arrays */
const collator = new Intl.Collator('en', {
numeric: true,
sensitivity: 'base'
})
I want to rename my all Audio files in particular folder in my drive by using google script.
How to get original name of file? And replace with new name that will erase first 23 words and remain all name as it was. I didn't understand how to do that.
I try following script.
function non_native_file_name_changer(folderID,fileName,fileType,iterator) {
var folder = DriveApp.getFolderById('ID');
var files = folder.getFilesByType(fileType);
var count = 1
while(files.hasNext()){
var file = files.next()
if(iterator === true){
file.setName(file.getName().slice(-23));
}else{
file.setName(fileName);
};
};
};
function start(){
var folder_ID = "ID";
var file_name = "Audio";
var file_type = "audio/amr";
var have_a_count = true;
var go = non_native_file_name_changer(folder_ID,file_name,file_type,have_a_count);
};
This not work...
Please help.
To call all files from folder but no run.
Please help.
You say you want the files from a specific folder but you didn't open a specific folder. What happens if you use
var id = "xxxxxxxxxxxxxx";
var files = DriveApp.getFolderById(id).getFiles();
while (files.hasNext()) {
var file = files.next();
Logger.log(file.getName());
}
I am working on a copy and paste feature for my website, so here is my problem. When i copy an image directly from a webpage it works as it should (the first if statement on the code), but if i am trying to copy a image from my own computer a i get a local path (like the one in the else statement)
$scope.pasteImage = function(eventPaste)
{
$scope.uploading = true;
var promises = [];
var items = (eventPaste.clipboardData || eventPaste.originalEvent.clipboardData).items;
for (var i = 0; i < items.length; i++)
{
var blob = null;
if (eventPaste.originalEvent.clipboardData.items[i].type.indexOf("image") == 0 || eventPaste.originalEvent.clipboardData.items[i] == 0)
{
blob = eventPaste.originalEvent.clipboardData.items[i].getAsFile();
}
else
{
var file = new File("file:///home/oem/testabc/vembly/source/server/images/pregnant.png")
console.log(file)
}
}
console.log(eventPaste)
console.log(blob)
var files = [blob];
uploadService.uploadMultiple(files)
}
so, my question is if its possible to transform that file (else statment) into a blob so i can use it in the uploadMultiple(files) funtction that i have.
No.
It would be a huge security problem if any website could use JavaScript to read data from any file path on your system it happened to guess existed.
I am new in Firebase.I haven't huge knowledge on the firebase.I want a bulk file uploader.
Suppose I have a file uploader in HTML.Using this a CSV/XML file will upload from a HTML.I convert this CSV/XML file in JSON(Array of JSON) then I want to upload this file in firebase.I have already converted and uploaded this file in firebase.But I face some problem, when file size is going big it takes too much time.
$rootScope.showLoader = true;
usSpinnerService.spin('spinner-1');
var ref = firebase.database().ref().child('Cars')
var newItem = $firebaseObject(ref);
var obj = {};
var count = 0;
for (var i = 0, len = jsonFile.length; i < len; i++) {
newItem[jsonFile[i]["DealerID"]] = jsonFile[i];
newItem.$save().then(function() {
count++;
if (count === (jsonFile.length - 1)) {
$rootScope.showLoader = false;
usSpinnerService.stop('spinner-1');
toastr.success('Successfully Upload this file');
}
})
}
This is my code. I use here angularfire service for this.
Can anyone give example how I optimize the time? It will be helpful for me. I can't use any server here.