I want to write a Firefox Add-on which removes some special characters from the default filename (highlighted in red in the image below) in the "Save Page As" dialog in Firefox. Does the Firefox SDK API offer some way to alter this filename?
Check the defaultString of the nsIFilePicker e.g.
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["#mozilla.org/filepicker;1"]
.createInstance(nsIFilePicker);
fp.init(window, "Select a File", nsIFilePicker.modeOpen);
fp.defaultString = defaultString; //Process the string as you want
fp.appendFilter(fileType, "*." + fileType);
var rv = fp.show();
Related
In the Documentation it is stated like this:
'FILEOPEN'(prompt,path,name,ext[,filters[,mode]])
But what parameters do you need to use to be able to display the dialog?
Any samples?
Parameters are documented in this page
Parameter
Description
prompt
Text to display in the title bar of the dialog.
path
Default directory for the file to be opened in the dialog.
name
Default name for the file to be opened in the dialog. Use the empty string ("") to avoid setting a default filename.
ext
Default extension (usually 3 characters, do not include the dot) for the file to be opened in the dialog. Use the empty string ("") to avoid setting a default extension.
filters
One or more filters in the following format: "text description" + $0a$ + "mask" [+$0a$ + "text description" + $0a$ + "mask" ...] The mask specifies an extension, in the format ".ext" or "."; two or more masks are separated with semicolons. The filter, if included, indicates which files will appear in the list. For example: REM Illustrate the use of the FILEOPEN() function REM Build filters for brc/arc and all files FILTER$="Binary Resource Files"+$0a$+".brc;.brf" FILTER$=FILTER$+$0a$+"ASCII Resource Files"+$0a$+".arc" FILTER$=FILTER$+$0a$+"All Files (.)"+$0a$+"." REM Starting directory is the default Directory FILE_DIR$="" REM Use FILEOPEN() to get name of file to open FILE_NAME$=FILEOPEN("Open Resource File",FILE_DIR$,"","",FILTER$) REM display file name returned PRINT FILE_NAME$
rem ' clientfile.txt
precision 6
tc! = bbjapi().getThinClient()
fs! = tc!.getClientFileSystem()
filter$ = ""
filter$ = filter$ + "Text Files (*.txt)"+$0a$+"*.txt"+$0a$
filter$ = filter$ + "HTML Files (*.htm;*.html)"+$0a$+"*.htm;*.html"+$0a$
filter$ = filter$ + "Image Files (*.png;*.jpg;*.bmp;*.gif)"+$0a$+"*.png;*.jpg;*.bmp;*.gif"+$0a$
filter$ = filter$ + "All Files (*.*)"+$0a$+"*.*"+$0a$
i = msgbox("Test client fileopen + copy file from client to server")
clientfile$ = fileopen("Pick a client file","","","",filter$,mode="client")
i = msgbox(clientfile$,0,"Selected client file")
if pos("::"=clientfile$) then goto eoj
cf! = fs!.getClientFile(clientfile$)
i = msgbox("Copy "+clientfile$+" to the server")
t = tim
serverfile$ = cf!.copyFromClient()
t = tim - t
t = t * 3600
serverfile = unt
open (serverfile)serverfile$
serverfile$ = fid(serverfile)(9)
bytes = dec(fin(serverfile)(1,4))
close (serverfile)
i = msgbox("Copied client file "+clientfile$+" to server file "+serverfile$+" ("+str(bytes)+" bytes; "+str(t)+" seconds)",0,"Copied from client to server")
i = msgbox("Test server fileopen + copy file from server to client")
serverfile$ = fileopen("Pick a server file","","","",filter$)
i = msgbox(serverfile$,0,"Selected server file")
if pos("::"=serverfile$) then goto eoj
clientfile! = new java.io.File(serverfile$)
clientfile$ = clientfile!.getName()
clientfile$ = filesave("Save to client","",clientfile$,"",filter$,mode="client")
if pos("::"=clientfile$) then goto eoj
i = msgbox("Copy server file "+serverfile$+" to client file "+clientfile$)
cf! = fs!.getClientFile(clientfile$)
cf!.copyToClient(serverfile$)
i = msgbox("Copied server file "+serverfile$+" to client file "+clientfile$,0,"Copied from server to client")
eoj:
release
I am trying to search-and-replace linked text from an old url to a new url.
It is not working and I have spent hours and hours. If I remove the "if (found)" it gives me "TypeError: Cannot read property 'getElement' of null" even though my files have text that is linked to this old_url.
Please, help me.
function myFunction() {
var old_url ="http://hurlx1.com";
var new_url ="http://urlxa.com";
var files = DriveApp.getFolderById("my folder id").getFilesByType(MimeType.GOOGLE_DOCS);
while (files.hasNext()) {
var file = files.next();
var doc = DocumentApp.openById(file.getId());
found=doc.getBody().findText(old_url);
if (found) {
var link_element = found.getElement().asText();
var start = found.getStartOffset();
var end = found.getEndOffsetInclusive();
var correct_link = link_element.getText().slice(start, end);
link_element.setLinkUrl(start, end, correct_link);
}
}
}
I believe your situation and goal as follows.
In your Google Document,
Text and hyperlink are the same with old_url.
Hyperlink is old_url. But the text is different from old_url.
You want to update old_url with new_url using Google Apps Script.
For this, how about this answer?
Modification points:
About your error message, when the text of old_url is not found in the Google Document with found=doc.getBody().findText(old_url);, found becomes null even when old_url is set as the hyperlink. Because findText searches the text on Document body, and that cannot search the hyperlinks set to the texts. I think that this is the reason of your issue.
In your script, var new_url ="http://urlxa.com"; is used. But when the link is set, correct_link is used like link_element.setLinkUrl(start, end, correct_link);. By this, new_url is not set.
When you want to update the text of http://hurlx1.com to new_url of var new_url ="http://urlxa.com";, it is required to also modify the text.
In your script, only the 1st old_url is updated. If there are several values of old_url in the Document, it is required to update them using the loop.
Specification of modified script:
This modified script can be used for the following patterns.
Text and hyperlink are the same with old_url.
In this case, the text value of old_url is also updated with old_url.
Hyperlink is old_url. But the text is different from old_url.
In this case, only the hyperlink of old_url is updated.
There are several texts with the hyperlink of old_url in the Google Document.
Modified script:
function myFunction() {
var old_url ="http://hurlx1.com";
var new_url ="http://urlxa.com";
var files = DriveApp.getFolderById("my folder id").getFilesByType(MimeType.GOOGLE_DOCS);
while (files.hasNext()) {
var file = files.next();
var doc = DocumentApp.openById(file.getId());
var body = doc.getBody();
// The following script is used for the situation that the text and hyperlink are the same with `old_url`.
var found = body.findText(old_url);
while (found) {
var link_element = found.getElement().asText();
var start = found.getStartOffset();
var end = found.getEndOffsetInclusive();
var correct_link = link_element.getText().slice(start, end);
link_element.setLinkUrl(start, end, new_url).replaceText(old_url, new_url);
found = body.findText(old_url, found);
}
// The following script is used for the situation that although the hyperlink is `old_url`, the text is different from `old_url`.
var text = body.editAsText();
for (var i = 0; i < text.getText().length; i++) {
if (text.getLinkUrl(i) == old_url) {
text.setLinkUrl(i, i + 1, new_url);
}
}
}
}
References:
replaceText(searchPattern, replacement)
findText(searchPattern, from)
editAsText()
I encountered a problem with setting the page header text containing ampersand like ‘a&b’. The text after ‘&’ disappears in the pdf maybe because it is the reserved key in Aspose. My code looks like this:
PageSetup pageSetup = workbook.getWorksheets().get(worksheetName).getPageSetup();
//calling the function
setHeaderFooter(pageSetup, parameters, criteria)
//function for setting header and footer
def setHeaderFooter(PageSetup pageSetup, parameters, criteria = [:])
{
def selectedLoa=getSelectedLoa(parameters)
if(selectedLoa.length()>110){
String firstLine = selectedLoa.substring(0,110);
String secondLine = selectedLoa.substring(110);
if(secondLine.length()>120){
secondLine = secondLine.substring(0,122)+"...."
}
selectedLoa = firstLine+"\n"+secondLine.trim();
}
def periodInfo=getPeriodInfo(parameters, criteria)
def reportingInfo=periodInfo[0]
def comparisonInfo=periodInfo[1]
def benchmarkName=getBenchmark(parameters)
def isNonComparison = criteria.isNonComparison?
criteria.isNonComparison:false
def footerInfo="&BReporting Period:&B " + reportingInfo+"\n"
if (comparisonInfo && !isNonComparison){
footerInfo=footerInfo+"&BComparison Period:&B " +comparisonInfo+"\n"
}
if (benchmarkName){
footerInfo+="&BBenchmark:&B "+benchmarkName
}
//where I encounterd the issue,selectedLoa contains string with ampersand
pageSetup.setHeader(0, pageSetup.getHeader(0) + "\n&\"Lucida Sans,Regular\"&8&K02-074&BPopulation:&B "+selectedLoa)
//Insertion of footer
pageSetup.setFooter(0,"&\"Lucida Sans,Regular\"&8&K02-074"+footerInfo)
def downloadDate = new Date().format("MMMM dd, yyyy")
pageSetup.setFooter(2,"&\"Lucida Sans,Regular\"&8&K02-074" + downloadDate)
//Insertion of logo
try{
def bucketName = parameters.containsKey('printedRLBucketName')?parameters.get('printedRLBucketName'):null
def filePath = parameters.containsKey('printedReportLogo')?parameters.get('printedReportLogo'): null
// Declaring a byte array
byte[] binaryData
if(!filePath || filePath.contains("null") || filePath.endsWith("null")){
filePath = root+"/images/defaultExportLogo.png"
InputStream is = new FileInputStream(new File(filePath))
binaryData = is.getBytes()
}else {
AmazonS3Client s3client = amazonClientService.getAmazonS3Client()
S3Object object = s3client.getObject(bucketName, filePath)
// Getting the bytes out of input stream of S3 object
binaryData = object.getObjectContent().getBytes()
}
// Setting the logo/picture in the right section (2) of the page header
pageSetup.setHeaderPicture(2, binaryData);
// Setting the script for the logo/picture
pageSetup.setHeader(2, "&G");
// Scaling the picture to correct size
Picture pic = pageSetup.getPicture(true, 2);
pic.setLockAspectRatio(true)
pic.setRelativeToOriginalPictureSize(true)
pic.setHeight(35)
pic.setWidth(Math.abs(pic.getWidth() * (pic.getHeightScale() / 100)).intValue());
}catch (Exception e){
e.printStackTrace()
}
}
In this case, I get only ‘a’ in the pdf header all other text after ampersand gets disappeared. Please suggest me with a solution for this. I am using aspose 18.2
We have added header on a PDF page with below code snippet but we did not notice any problem when ampersand sign is included in header text.
// open document
Document document = new Document(dataDir + "input.pdf");
// create text stamp
TextStamp textStamp = new TextStamp("a&bcdefg");
// set properties of the stamp
textStamp.setTopMargin(10);
textStamp.setHorizontalAlignment(HorizontalAlignment.Center);
textStamp.setVerticalAlignment(VerticalAlignment.Top);
// set text properties
textStamp.getTextState().setFont(new FontRepository().findFont("Arial"));
textStamp.getTextState().setFontSize(14.0F);
textStamp.getTextState().setFontStyle(FontStyles.Bold);
textStamp.getTextState().setFontStyle(FontStyles.Italic);
textStamp.getTextState().setForegroundColor(Color.getGreen());
// iterate through all pages of PDF file
for (int Page_counter = 1; Page_counter <= document.getPages().size(); Page_counter++) {
// add stamp to all pages of PDF file
document.getPages().get_Item(Page_counter).addStamp(textStamp);
}
// save output document
document.save(dataDir + "TextStamp_18.8.pdf");
Please ensure using Aspose.PDF for Java 18.8 in your environment. For further information on adding page header, you may visit Add Text Stamp in the Header or Footer section.
In case you face any problem while adding header, then please share your code snippet and generated PDF document with us via Google Drive, Dropbox etc. so that we may investigate it to help you out.
PS: I work with Aspose as Developer Evangelist.
Well, yes, "&" is a reserved word when inserting headers/footers in MS Excel spreadsheet via Aspose.Cells APIs. To cope with your issue, you got to place another ampersand to paste the "& (ampersand)" in the header string. See the sample code for your reference:
e.g
Sample code:
Workbook wb = new Workbook();
Worksheet ws = wb.getWorksheets().get(0);
ws.getCells().get("A1").putValue("testin..");
String headerText="a&&bcdefg";
PageSetup pageSetup = ws.getPageSetup();
pageSetup.setHeader(0, headerText);
wb.save("f:\\files\\out1.xlsx");
wb.save("f:\\files\\out2.pdf");
Hope this helps a bit.
I am working as Support developer/ Evangelist at Aspose.
Doesn't seem like iTunes connect has basic exporting of user emails from Prerelease > External testers
Needed to export emails to CSV
Does anyone have a script or workaround solution?
Thanks!
You can use pilot (from Fastlane) to do that :
To export in a CSV file: fastlane pilot export
$ fastlane pilot list
+--------+--------+--------------------------+-----------+
| Internal Testers |
+--------+--------+--------------------------+-----------+
| First | Last | Email | # Devices |
+--------+--------+--------------------------+-----------+
| Felix | Krause | felix#krausefx.com | 2 |
+--------+--------+--------------------------+-----------+
+-----------+---------+----------------------------+-----------+
| External Testers |
+-----------+---------+----------------------------+-----------+
| First | Last | Email | # Devices |
+-----------+---------+----------------------------+-----------+
| Max | Manfred | email#email.com | 0 |
| Detlef | Müller | detlef#krausefx.com | 1 |
+-----------+---------+----------------------------+-----------+
Just use console get Email, First Name, Last Name
Paste this into console
https://gist.github.com/creaoy/80d1092283a5d0fa1070
Upon trial and error (because I'm desperate), I found a way out, the low tech way.
Go to Activity > iOS History > All Builds > Testers
This is the page where you see all of your external and internal testers' emails, name, status, sessions, crashes and devices. Select all rows and paste them into excel. It will display all information in each cell nicely :) Select the first column in excel and you have all the emails only.
I expanded creaoy's script to include the Status (Notified/Installed x.xx). Still works for me today.
Scroll all the way down so all testers are loaded. Then paste this in Safari's error console and hit enter.
var text = '';
$('.col-email').each(function(index,el) {
if (index == 0) {
text = 'Email, First Name, Last Name, Status\n';
}
else {
//Email
text = text + $.trim($(el).find("a").text()) + ',';
//First Name
text = text + $.trim($($($($('.col-name')[index]).find("span")[0]).find("span")[0]).text()) + ',';
//Last Name
text = text + $.trim($($($($('.col-name')[index]).find("span")[0]).find("span")[1]).text()) + ',';
//Status
text = text + $.trim($($($($('.col-status')[index]).find("div")[0]).find("span")[0]).text()) + '\n';
}
});
var a = document.createElement("a");
var file = new Blob([text], {type: 'text/csv'});
a.href = URL.createObjectURL(file);
a.download = name; a.click();
Not as yet. You can only import a csv file but not create one from the users there.
You can copy the rows, edit them in TextEdit/Notepad in the format:
fistname,lastname,email
and save that as csv to use when you want to import those emails later.
It would be good if they implemented it to do this automatically, or at least having the option to send the updates to specific groups that you can create.
I made a little console hack that extracts just the emails. Improve to your liking :-)
https://gist.github.com/larsparendt/a67d25b1611db67ba67b
Some great answers, but wanted to add another option. BoardingBot is a tool that lets you send TestFlight invites automatically, as well as emails to your beta testers. So this might fill your need for contacting your beta testers.
Disclaimer: I'm the founder of BoardingBot :)
Since iTunes Connect is now an angular app, many of the answers on this page no longer work. However if you have the Angular/Batarang extension for Chrome you can paste this script in the console (cmd+i) and it will spit out a csv. Note that first you have to inspect an item in the list (cmd + shift + c) to get a reference to $scope. Also don't forget to scroll down to make the page auto-load the whole list.
var text = '';
angular.forEach($scope.filteredTesters, function(val) {
text += val.firstName.value + ',';
text += val.lastName.value + ',';
text += val.emailAddress.value + '\n';
});
var a = document.createElement("a");
var file = new Blob([text], {type: 'text/csv'});
a.href = URL.createObjectURL(file);
a.download = name; a.click();
Edit:
The below method is flakey - there is a great ruby gem for managing testflight testers called Fastlane pilot. I woudl recommend looking into that instead: https://github.com/fastlane/fastlane/tree/master/pilot
Found a google chrome extension that will do the job:
Table capture:https://chrome.google.com/webstore/detail/table-capture/iebpjdmgckacbodjpijphcplhebcmeop/reviews?hl=en
Also needed to filter out duplicates, which can be done using Google spreadsheets
If you just need the emails and have a text editor with regex replacement you can do this
Scroll to the bottom of the list in itunesconnect so you get all rows
Copy all the rows into text editor of your choice (I used sublime text)
replace ^.*\n\n with <empty string>. This removes all names
replace \n\s\n with ,.
replace \n with ,.
and you're left with a CSV of all the emails
if like me you also needed the date this is the code you need:
var text = '';
$('.col-email').each(function(index,el) {
if (index == 0) {
text = 'Email, First Name, Last Name, Status, Date\n';
}
else {
//Email
text = text + $.trim($(el).find("a").text()) + ',';
//First Name
text = text + $.trim($($($($('.col-name')[index]).find("span")[0]).find("span")[0]).text()) + ',';
//Last Name
text = text + $.trim($($($($('.col-name')[index]).find("span")[0]).find("span")[1]).text()) + ',';
//Status
text = text + $.trim($($($($('.col-status')[index]).find("div")[0]).find("span")[0]).text()) + ',';
//Date
text = text + '\"' + $.trim($($($($('.col-status')[index]).find("div")[0]).find("span")[2]).text()) + '\"\n';
}
});
var a = document.createElement("a");
var file = new Blob([text], {type: 'text/csv'});
a.href = URL.createObjectURL(file);
a.download = name; a.click();
I came up with a jQuery solution to output this data to the console in CSV format. It is dependent on the way that the pages selectors are set up but as of now (Sep. 2017), it runs great.
Open up the console on your browser (I use Chrome), copy and paste this code in, hit enter. Quick and dirty.
Edit
I borrowed some code from guido's answer here that triggers an automatic download after hitting enter.
output = "email,first name,last name\n";
jQuery('table.table-itc-testers tr[ng-repeat*="itcUser"]').each(function(){
row = [];
//Email Address
row.push(jQuery(this).find('span a[href*="users_roles"]').text());
// First and last name
full_name = jQuery(this).find('td.sorted > span:not(.ng-hide)');
// If only name is filled out
if(full_name==""){
row.push("");
row.push("");
} else {
row.push(full_name.clone().children().remove().end().text().trim());
row.push(full_name.find('span.lastname').text());
}
output += row.join(",") + "\n";
});
var a = document.createElement("a");
var file = new Blob([output], {type: 'text/csv'});
a.href = URL.createObjectURL(file);
a.download = 'external_testers.csv'; a.click();
Quick Update with a new answer: iTunes Connect now has an easy-to-use download button on the right side of the page!
Can someone please tell me how to create a file and make it available for download via browser button?
I have read about FileWriter but not found any proper example how to use it
and I found a post How to use the dart:html library to write html files?
but the answer just refers to html5lib which just answers how to parse a String to HTML but not how to save as a file.
help appreciated. Am I missing something or there is no example for that usecase??
Personally, I use a combination of Blob, Url.createObjectUrlFromBlob And AnchorElement (with download and href properties) to create a downloadable file.
Very simple example:
// Assuming your HTML has an empty anchor with ID 'myLink'
var link = querySelector('a#myLink') as AnchorElement;
var myData = [ "Line 1\n", "Line 2\n", "Line 3\n"];
// Plain text type, 'native' line endings
var blob = new Blob(myData, 'text/plain', 'native');
link.download = "file-name-to-save.txt";
link.href = Url.createObjectUrlFromBlob(blob).toString();
link.text = "Download Now!";
As alluded to by Günter Zöchbauer's comment, an alternative to using Blobs is to base64-encode the data and generate a data URL yourself (at least for file sizes that are well within the data URL limits of most browsers). For example:
import 'dart:html';
Uint8List generateFileContents() { ... }
void main() {
var bytes = generateFileContents();
(querySelector('#download-link') as AnchorElement)
..text = 'Download File'
..href = UriData.fromBytes(bytes).toString()
..download = 'filename';
}
Also note that if you do want to use a Blob and want to write binary data from a Uint8List, you are expected to use Blob([bytes], ...) and not Blob(bytes, ...). For example:
var bytes = generateFileContents();
var blob = Blob([bytes], 'application/octet-stream');
(querySelector('#download-link') as AnchorElement)
..text = 'Download File'
..href = Url.createObjectUrlFromBlob(blob)
..download = 'filename';