I'm trying to do automate my file saving to saveAs file .rgba in photoshop. So far I only manage to modify the code to save out .sgi files. Please help. Thanks
var Name = app.activeDocument.name.replace(/\.[^\.]+$/,'');
var Path = app.activeDocument.path;
var saveFile = File(Path + "/" + Name +".sgi");
var saveFile2 = File(Path + "/" + Name +".rgba");
if(saveFile2.exists)
{
saveFile2.remove();
}
rgbaSaveOptions = new SGIRGBSaveOptions();
activeDocument.saveAs(saveFile, rgbaSaveOptions, true, Extension.LOWERCASE);
saveFile.rename(Name+'.rgba');
Related
I am using the script below to export a sheet as Excel file but the output file name is always Document Name + Sheet Name ("Exported - Report.xlsx"). How can I modify this to only use the sheet name as file name of the exported file ("Report.xlsx")?
function ExportSheet()
{
var SheetApp = SpreadsheetApp.getActive();
SheetApp.rename("Exported");
ShtURL = SheetApp.getUrl();
ShtID = SheetApp.getId();
ShtGID = SheetApp.getSheetId();
var url = ShtURL.toString().replace("/edit", "/export?format=xlsx&gid=" + ShtGID);
var html = HtmlService.createHtmlOutput('<html><script>'
+'window.close = function(){window.setTimeout(function(){google.script.host.close()},9)};'
+'var a = document.createElement("a"); a.href="'+url+'"; a.target="_blank";'
+'if(document.createEvent){'
+' var event=document.createEvent("MouseEvents");'
+' if(navigator.userAgent.toLowerCase().indexOf("firefox")>-1){window.document.body.append(a)}'
+' event.initEvent("click",true,true); a.dispatchEvent(event);'
+'}else{ a.click() }'
+'close();'
+'</script>'
// Offer URL as clickable link in case above code fails.
+'<body style="word-break:break-word;font-family:sans-serif;">Failed to open automatically. Click here to proceed.</body>'
+'<script>google.script.host.setHeight(40);google.script.host.setWidth(410)</script>'
+'</html>')
.setWidth( 90 ).setHeight( 1 );
SpreadsheetApp.getUi().showModalDialog( html, "Opening ..." );
SheetApp.rename("Template");
}
In your situation, unfortunately, using the URL of ShtURL.toString().replace("/edit", "/export?format=xlsx&gid=" + ShtGID), the filename cannot be directly changed. So, in this case, how about the following modification?
Modified script:
function ExportSheet() {
var SheetApp = SpreadsheetApp.getActive();
SheetApp.rename("Exported");
ShtURL = SheetApp.getUrl();
ShtID = SheetApp.getId();
ShtGID = SheetApp.getSheetId();
var url = ShtURL.toString().replace("/edit", "/export?format=xlsx&gid=" + ShtGID);
// --- I modified below script.
var blob = UrlFetchApp.fetch(url, { headers: { authorization: "Bearer " + ScriptApp.getOAuthToken() } }).getBlob();
var file = DriveApp.createFile(blob.setName(SheetApp.getSheets()[0].getSheetName()));
url = "https://drive.google.com/uc?export=download&id=" + file.getId();
// ---
var html = HtmlService.createHtmlOutput('<html><script>'
+ 'window.close = function(){window.setTimeout(function(){google.script.host.close()},9)};'
+ 'var a = document.createElement("a"); a.href="' + url + '"; a.target="_blank";'
+ 'if(document.createEvent){'
+ ' var event=document.createEvent("MouseEvents");'
+ ' if(navigator.userAgent.toLowerCase().indexOf("firefox")>-1){window.document.body.append(a)}'
+ ' event.initEvent("click",true,true); a.dispatchEvent(event);'
+ '}else{ a.click() }'
+ 'close();'
+ '</script>'
// Offer URL as clickable link in case above code fails.
+ '<body style="word-break:break-word;font-family:sans-serif;">Failed to open automatically. Click here to proceed.</body>'
+ '<script>google.script.host.setHeight(40);google.script.host.setWidth(410)</script>'
+ '</html>')
.setWidth(90).setHeight(1);
SpreadsheetApp.getUi().showModalDialog(html, "Opening ...");
SheetApp.rename("Template");
file.setTrashed(true); // Added
}
In this modification, the converted XLSX is created as a temporal file. Here, the filename is changed. And, the file is downloaded using the URL of the created file. The temporal file is removed.
Note:
From your script, I thought that you might have wanted to use the sheet name of the 1st tab. But, if you want to give the specific filename, please modify SheetApp.getSheets()[0].getSheetName() of blob.setName(SheetApp.getSheets()[0].getSheetName()).
I am uploading all the files in Azure blob storage. I am working on Dynamics 365 and want to download the file stored in Azure blob when I click the button in my Dynamics environment.
function getSelectedItems(selectedItems) {
for (i = 0; i < selectedItems.length; i++)
{
var selectedItem = selectedItems[i];
// Here you can use the information below to open a new window or whatever!
alert("Id=" + selectedItem.Id + "\nName=" + selectedItem.Name + "\nTypeCode=" + selectedItem.TypeCode.toString() + "\nTypeName=" + selectedItem.TypeName);
var new_fileName = selectedItem.Id;
var new_fileurl = '';
getUrlOfAttachmentFileFromBlob(new_fileurl,new_fileName);
}
}
function getUrlOfAttachmentFileFromBlob(new_fileurl,new_fileName) {
var fileHyperlink = '';
var blobUri = 'https://' + 'Storage_Account_Name' + '.blob.core.windows.net';
var containerName = 'trial';
var sas_token = 'sastoken' ;
var blobService = AzureStorage.Blob.createBlobServiceWithSas(blobUri, sas_token);
//.withFilter(new AzureStorage.Blob.ExponentialRetryPolicyFilter());
var downloadLink = blobService.getUrl(new_fileName, new_fileurl.replace('/'+containerName+'/',''), sas_token);
if (downloadLink != null)
{
alert("Link " + downloadLink);
downloadURI(downloadLink, new_fileName);
}
}
function downloadURI(uri, name)
{
var link = document.createElement("a");
link.setAttribute('download', name);
link.href = uri;
document.body.appendChild(link);
link.click();
}
I tried this code, but it's not working.
To add more details, I am calling the getSelectedItems function when I click the button inside the Dynamics environment. In this function, I am also getting the unique ID of the selected row in the grid. The unique ID is the name of the file in Azure blob storage.
Can you please provide me some reference on how can I download the files to the local machine using JavaScript?
I have a Grid view With Name time , device , Upload control columns , When i click upload in Grid view , files will be uploaded and saved in a folder, but i need to save the file with name_time_device..
How to do it any help??
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
//FileUploadData.tName = Request.QueryString["name"];
//string fname = context.Server.MapPath("~/FileUploads/") + FileUploadData.Name + "_" + FileUploadData.Id + "/" + DateTime.Now.ToString("ddMMyyyy") + "/" + FileUploadData.deviceID + "_" +
string fname = context.Server.MapPath("~/uploads/" + file.FileName);
file.SaveAs(fname);
}
context.Response.ContentType = "application/x-zip-compressed";
context.Response.Write("File Uploaded Successfully!");
}
File uploading and saving i am doing in javascript. the file is zipped..and saving it in uploads folder, but it need to be saved with name_id_date_device.zip..
I am using a function In that function i am using ajax call , above code is my generic handler to save the files..
file saving is from function, here while saving only i need to pass id_name_device so which ever user clicks upload and upload files his file will be saved by his id_name_device.zip..
Help??
Can you please speicify you are having problem in getting name, time, device from gridview or you have issue with file saving with name "name_id_date_device.zip"?
if you problem is saving file with a specific name and you are ok to get name, time or device from gridview then you should change this:
string fname = context.Server.MapPath("~/uploads/" + file.FileName);
TO
string fname = context.Server.MapPath("~/uploads/" + "name_id_date_device.zip");
in this way your file will be saved with this given name.
if you want to add your flag with file name just concat it with your filename when you are saving.
string fname = context.Server.MapPath("~/uploads/" + "what_flag_name_time" + file.FileName);
.and if you have anyother problem please be more specific. Thanks
I have this javascript that saves a copy of a file. I need it to run automatically every time a file is opened and also save that copy to a specific folder. Here's what I have so far:
var myDoc = app.activeDocument;
myDoc.save();
var myFile = myDoc.fullName;
var myDate = new Date;
var mySuffix = "_Backup_" + myDate.getDate() + "_" + myDate.getMonth() + "_" + myDate.getHours() + "-" + myDate.getMinutes() + "-" + myDate.getSeconds() +".indd"
var myBaseName = myDoc.fullName.fsName.match(/(.*)\.[^\.]+$/)[1] ;
var myNewFile = new File(myBaseName + mySuffix);
myFile.copy(myNewFile);
So what you want is called an event listener. (See the section "Working with event listeners" in the InDesign scripting guide.)
Save your .jsx file in the "startup scripts" folder. (On a Mac, it's in /Applications/Adobe InDesign CS6/Scripts/startup scripts/.)
#targetengine "session"
app.addEventListener('afterOpen', function(myEvent) {
// afterOpen fires twice: once when the document opens
// and once when the window loads. Choose one,
// ignore the other.
// See: http://forums.adobe.com/message/5410190
if (myEvent.target.constructor.name !== 'Document') {
return;
}
var myDoc = myEvent.target;
// Continue on with your code from here
}
How to create a new file in appcelerator titanium.
var Settings = Titanium.Filesystem.getFile(Titanium.Filesystem.tempDirectory,'Settings');
Ti.API.info("Created Settings: " + Settings.createDirectory());
Ti.API.info('Settings ' + Settings);
var newFile = Titanium.Filesystem.getFile(Settings.nativePath,'Settings.txt');
newFile.write('line 1\n');
Ti.API.info('newfile: '+newFile.read());
The Above code is not working...
Try creating the file before writing to the file:
var Settings = Titanium.Filesystem.getFile(Titanium.Filesystem.tempDirectory,'Settings');
Ti.API.info("Created Settings: " + Settings.createDirectory());
Ti.API.info('Settings ' + Settings);
var newFile = Titanium.Filesystem.getFile(Settings.nativePath,'Settings.txt');
newFile.createFile();
if (newFile.exists()){
newFile.write('line 1\n');
Ti.API.info('newfile: '+newFile.read());
}
Using newFile.createFile(); will throw error. It seems depricated in 3.0 as I did not find it woking with me. I tried newfile.write('Some data'); and it worked.