InDesign jsx opening files with specific options - macos

I am trying to batch process .indd files created many years ago on old versions of InDesign.
I have 2 goals:
Open .indd files without having to manually click on the
dialogs:- "Update linked images? (select 'update')", "font errors
(select 'Skip')"
Save files to .indd, current versions native format, attaching _cc2020 to their original filename.
Here's how I am doing so far:
// Opening files
// specify source folder
path = '~/Desktop/source_dir';
// list files in the folder
var my_folder = new Folder(path);
list_of_files = my_folder.getFiles();
// open file(s)
fileObj = app.open(list_of_files);
// saving files
// get current documents
myDoc = app.activeDocument;
// save current document with specific name
myDoc.save(File('~/Desktop/test01.indd'));
I could not find ways to suppress (or provide preset default value to) the two dialogs.
Could someone please enlighten me how I can achieve this?
ps. I found providing false as second argument will suppress font dialogs, but "update images" dialogs still persists.
// open file(s)
fileObj = app.open(list_of_files, false);
resource I've been referring to https://wwwimages2.adobe.com/content/dam/acom/en/devnet/indesign/sdk/cs6/scripting/InDesign_ScriptingGuide_JS.pdf

Suppress dialogues with
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

Related

Automate a reoccuring manual task (generate order number based on name) in Visual Studio

I'm currently working on a EpiServer project where we use the ContentType attribute to set the DisplayName and Order of the blocks. The Order is based on the name of the block. Here's an example:
[ContentType(
DisplayName = "My First Block",
Order = 133536,
GUID = "0f02e38a-a6e2-4333-9bd1-c61cf573d8d3",
Description = "Just an example block.",
GroupName = "Blocks.Content"
)]
public class MyFirstBlock : BaseBlock
{
}
Apparently EpiServer can't sort the blocks alphabetically so we generate the order based on the DisplayName as a work around. A formula was invented to determine the order. One colleague has written a JavaScript function that can be used to generate the order number:
function getEPiOrderNumber(value) {
var alphabeticalIndex = function (character) {
return character.toLowerCase().charCodeAt() - 96;
};
var firstSection = alphabeticalIndex(value[0]);
var secondSection = alphabeticalIndex(value[1]) + 10;
var thirdSection = alphabeticalIndex(value[2]) + 100;
return `${firstSection}${secondSection}${thirdSection}`;
}
This function can be executed in the console of a browser. Better than having to calculate the order by hand, but this requires that I switch to a browser, open the console, paste this code and execute it and finally copy the result and paste it in the model I'm working on.
I figured it would be much more convenient to be able to do generate the order number from within VS. I have been looking into using Visual Studio Extensions but can't really find anything that is to my liking.
The most optimal solution would be to be able to select the (part of the) DisplayName, right click and select a new command from the context menu that will generate the order and paste it at the correct location. Or place it on the clip board so I can easily paste it in the right location myself. A pop-up displaying the order would be fine as well.
Is this even possible?
Another option could be a new command in one of the toolbar menu's, say Tools, that would display a small window where I can enter/ paste the text and to have it generate the order that I can then paste in the code.
I have figured out how to add an Custom Command to the Tools menu and how I could generate the code and display it, but how can I enter the text? Or is it maybe possible to retrieve selected text from the editor window? That would solve my problem as well.
If anyone could point me in the right direction, that would be great!
PS. I'm not too happy with the title of this question so I'm open to suggestions if anyone can think of a title that better describes my question.
You could retrieve selected text from Visual Studio editor window with following code.
DTE dte = (DTE)this.ServiceProvider.GetService(typeof(DTE));
string text = "";
if (dte.ActiveDocument != null)
{
var selection = (TextSelection)dte.ActiveDocument.Selection;
text = selection.Text;
}

How can I copy a list of the open tab titles in Firefox?

I've been trying to copy a list of the open tab titles in Firefox, but I cannot seem to find a solution.
The closest I've came is by using: https://addons.mozilla.org/en-us/firefox/addon/send-tab-urls/
But this add-on copies other details in addition to the tab titles.
I cannot find a solution anywhere for this simple task.
Does anybody have any tips on how to accomplish this?
You can use the Multiple Tab Handler addon. Right click, then Copy URI of All Tabs. You will need to tweak the addon's options to output the result in the format you want.
Or alternatively, open up Firefox's Scratchpad developer tool (Shift-F4) and use the following code in browser environment.
// -sp-context: browser
var tabs=Array.from(gBrowser.visibleTabs);
var urls=tabs.map(t=>gBrowser.getBrowserForTab(t).currentURI.spec);
var titles=tabs.map(t=>gBrowser.getBrowserForTab(t).contentTitle);
urls.join("\n");
titles.join("\n");
The variable titles will contain the array of titles of the currently visible tabs (i.e. tabs in the current tab group). Use Display to view the contents of the variable.
Simple ..... here is an example
for (var i = 0, len = window.gBrowser.tabs.length; i < len; i++) {
console.log(window.gBrowser.tabs[i].label);
}
There are a few more tab related functions in my FoxyTab

How do I trap an error when OneDrive image renders file.OpenAsync error

In a project I try to give users the option to select images from their personal libraries. Nothing special as such.
This goes perfectly when the user selects the desired image from a local imagelibrary. But when images are selected from OneDrive, an error occurs, and I'm not able to trap the error. The source of the error seems to be in the file.OpenAsync method.
It seems like there may be a relation with the size of the selected image, but I cannot tell, as i'm not able to catch the error.
Here's the codesnippet (it's taken from the XAML image SDK samples in fact)
Dim picker As New FileOpenPicker With {.ViewMode = PickerViewMode.Thumbnail, .SuggestedStartLocation = PickerLocationId.PicturesLibrary}
'picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary
picker.FileTypeFilter.Add(".png")
picker.FileTypeFilter.Add(".jpeg")
picker.FileTypeFilter.Add(".jpg")
picker.FileTypeFilter.Add(".bmp")
Dim wBitMap as new WritableBitmap(200,200)
Dim file As StorageFile = Await picker.PickSingleFileAsync()
' Ensure a file was selected
If file IsNot Nothing Then
Try ' Set the source of the WriteableBitmap to the image stream
Using fileStream As IRandomAccessStream = Await file.OpenAsync(Windows.Storage.FileAccessMode.Read)
Await wBitmap.SetSourceAsync(fileStream)
wBitmap.Invalidate()
vwImage.Source = wBitmap
End Using
Catch e1 As TaskCanceledException
' The async action to set the WriteableBitmap's source may be canceled if the user clicks the button repeatedly
End Try
End If
As you can see, there is a try-catch in place, but nonetheless a non-trapped error pops up, and stepping through, I can detect that it happens in the line
Await file.OpenAsync(Windows.Storage.FileAccessMode.Read)
Now my question is: how do I catch this error? Am I right that the line above is the source of the error? And if not so: what is and how to overcome?
After a lot of experimenting, I think I found the solutoion.
When a StorgeFile is selected to be used as the source for an image, it is wise to check the StorageFile.Attributes.
Files that are selected will carry an Attributes value. In the case of a file from OneDrive, the Attributes value was 544 (the value that you get when combining Archive and LocallyIncomplete. So that file has to be downloaded first, and then it will be available to use.
This is explained here:
Link to the MSDN documentation on StorageFile.Attributes

External Images Referencing in ACCDB

I have a database application making use of VBA code that has reached its 2GB size limitation with image attachments on a per-record basis. We're wanting to have all forms in the application move away from "uploading" images as attachments for records, and instead upload them to a directory on a network server and reference the image files in the forms.
At this point, I'm trying to figure out the best way to approach this. Is it feasible to have the user somehow pull up an "Upload" dialog through an Access form? I've tried a couple cobbled-together solutions for Open File dialogs in VBA, but they've never quite worked properly.
Summary: File type is ".ACCDB", I need to allow users to upload images in a New Record creation form, have the images stored in a Network directory, and accessed on-the-fly throughout the application.
Thanks in advance.
From a general database point of view, you should not store images directly in a database, unless they are very small (less than 1 MB approximately), and you actually have the space to store them. The most common practice is to store the image path in the database, and then load those images directly from your the file directory where the images are stored when needed. It will add another level of complexity, but will reduce your DBs size radically.
Update:
This code allows the user to click some element frame in the form, store the path in the DB (with path as the username.jpg), and display the picture to the user afterwards in the clicked frame:
Private Sub SignatureFrame_Click()
On Error GoTo ErrorHandler
' Get path for the new picture from a dialog box
Dim Path As String
Dim fd As FileDialog
Dim ffs As FileDialogFilters
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
Set ffs = .Filters
With ffs
.Clear
.Add "Pictures", "*.jpg"
End With
.AllowMultiSelect = False
If .Show = False Then Exit Sub
Path = .SelectedItems(1)
End With
' Update the picture in the user interface
Me![SignatureFrame_Click].Picture = Path
' Copy the signature into the local Signature folder of the DB
Dim fs As Object
Dim oldPath As String, newPath As String, file As String
oldPath = Path 'Full path the file is located in
newPath = CurrentProject.Path & "\Signatures\Users\" & Screen.ActiveForm.UserName & ".jpg" 'Folder and path to copy file to
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CopyFile oldPath, newPath 'This file was an .jpg file
Set fs = Nothing
' Set the new picture path for the form
Screen.ActiveForm.SignaturePath = newPath
Exit Sub
ErrorHandler:
MsgBox "Could not upload the image. Please check that the file format is of type jpg."
Resume Next
End Sub
Then at some later point in some other form you can retrieve the image like this:
Me!SignatureFrame.Picture = CurrentProject.Path & "\Signatures\username.jpg"
PS: The code has been translated in the SO editor, so I cannot guarantee that there are no mistakes.
Hope that helps!

Disable Print button in HtmlHelp

I'm performing maintenance on a legacy MFC application. We have a need to disable the Print button in the Help dialog. There is no printer connected to the system and the application crashes if the user presses the Print button in the help window.
The code just uses the standard HtmlHelpA method to bring up the Windows Help dialog:
void CNiftyView::OnHelp()
{
CString csHelpFile;
csHelpFile.Format( "%s/NiftyHelp.chm", NiftyDoc::GetHelpPath() );
::HtmlHelpA( m_hWnd, csHelpFile, HH_HELP_CONTEXT, IDH_NIFTY_SECTION );
}
I've found information that we can suppress the Print button with some code in the Help HTML stylesheet (http://www.sagehill.net/docbookxsl/HtmlHelp.html). But that would require recompiling the help file, and I'd prefer to not do that. I also found some information that says you can customize the HTML Help Viewer by manipulating each pane's HH_WINTYPE structure, but no information on how you actually do that (http://msdn.microsoft.com/en-us/library/ms524435%28v=vs.85%29.aspx).
Is there some way to disable that Print button in the HTML Help viewer programatically?
You can display your CHM help file without the Print button as follows:
Call HtmlHelp with the HH_GET_WIN_TYPE command to get a pointer to a HH_WINTYPE structure containing the HTML Help Viewer parameters defined in your CHM file.
Copy the returned structure. (Modifying the returned structure directly won't work.)
Modify the fsToolBarFlags member of the structure to exclude the HHWIN_BUTTON_PRINT value.
Pass the modified HH_WINTYPE structure back to the HtmlHelp function using the HH_SET_WIN_TYPE command.
Example C++ code*:
HH_WINTYPE *pwt = NULL;
LPCWSTR pszFile = L"MyFile.chm";
LPCWSTR pszWin = L"MyFile.chm>Main"; // "Main" is the window type defined in the CHM file
// Get the window type definition
HWND hWndHelp = HtmlHelp(NULL, pszWin, HH_GET_WIN_TYPE, (DWORD) &pwt);
if (pwt) {
// Copy the contents of the returned structure
HH_WINTYPE wt = *pwt;
// Remove the "Print" toolbar button from the window definition
wt.fsToolBarFlags &= ~HHWIN_BUTTON_PRINT;
wt.cbStruct = sizeof(wt); // force the correct size
// Set the new window type
hWndHelp = HtmlHelp(NULL, pszFile, HH_SET_WIN_TYPE, (DWORD) &wt);
// Display help
hWndHelp = HtmlHelp(NULL, pszFile, HH_DISPLAY_TOPIC, NULL);
}
I almost don't know C++, so it's very amateur code. Please fell free to edit and improve it.
More examples of using HH_WINTYPE, HH_GET_WIN_TYPE and HH_SET_WIN_TYPE:
How To Programmatically Create a Tri-pane HTML Help Window
How to use the unmanaged HTML Help API from a managed Visual C# application

Resources