I'm working on my first AppleScript (2.5) and can't seem to resolve my issue here.
I'm trying to open each markdown file in a folder and export to PDF. Opening the file with the specified application works, but I get 'The variable PDF is not defined' before the export happens.
I've tried four or five different sets of commands, from permutations on the save command to trying to use 'export' as some have suggested, but this form here appears to be the closest I've come to success. (Anytime I use export I get "Expected end of line, etc. but found identifier" and the word 'export' highlighted)
I appreciate any insight
tell application "Finder"
set sourceFolder to "Path:To:SourceFolder"
set MDFiles to files of folder sourceFolder whose name extension is "md"
end tell
repeat with f in MDFiles
set filePath to f as text
set newFilePath to (text 1 thru -2 of filePath) & "pdf"
tell application "MacDown"
open f
save f in file newFilePath as PDF
close f saving no
end tell
end repeat
After following #vadian's advice, it appears that the application does not have the ability to save to PDF.
Related
I encountered the following issue:
When accidentally passing a folder path to the Documents.Open function in VBA Word I get the runtime error 5174 as one would expect.
However all files with names that begin with an underscore get deleted in that moment from that folder.
To replicate:
Assume folder C:/Test/
In said folder have two files:
test.txt
_test.txt
In Word VBA execute the command:
Documents.Open("C:/Test/")
(As part of a subroutine or in the immediate window.)
Result: Runtime Error 5174 and _test.txt is now missing.
Note: Passing a nonexisting file like "C:/Test/abc.txt" or a wrong folder path like "C:/Test" (without the last slash) will not have this effect and won't cause the runtime error.
I have only tested this on one system on a network drive under windows 10 with Microsoft Professional Plus 2019. It's entirely possible that it's an issue with the file system. Does anyone have any suggestions as to why is this happening? I now included the workaround to check if I'm passing a folder, but it's still unnerving.
The Documents.Open method opens the specified document and adds it to the Documents collection. It is designed to take the file path, not a folder. If you want to allow users to pick file(s) you may consider using the file open dialog. The FileOpenDialog triggered by your code which opens a folder for picking files allows specifying file formats that should be supported and visible via the dialog window.
Set dlgSaveAs = Application.FileDialog(msoFileDialogFilePicker)
dlgSaveAs.Filter = "Text Files (.txt)|*.txt|Word Documents (.docx)|*.docx|Word Template (.dotx)|*.dotx|All Files (*.*)|*.*"
dlgSaveAs.ValidateNames = true
Res = dlgSaveAs.Show
Problem: Word sometimes doesn't choose "Single File Web Page" format automatically for .mht files.
Description:
When opening files in Word application there is an option to select file conversion format:
For the .mht files to be correctly decoded/viewed i noticed that selecting format "Single File Web Page" works perfect.
Is it possible to achieve this programmatically? Lets say I would like to open the .mht file in word application, and use word's converter to treat it as a "Single File Web Page" file.
So far I have found that Documents.Open method (https://learn.microsoft.com/en-us/office/vba/api/word.documents.open) accepts parameter "Format". But it seem like it doesn't have the format I need. The closest I see is wdOpenFormatWebPages(7), but it is not the same as "Single File Web Page"
https://learn.microsoft.com/en-us/office/vba/api/word.wdopenformat
VB:
Documents.Open FileName:="C:\test.mht", format:=7
C#:
Application app = new Application();
Document document = app.Documents.Open(FileName: #"C:\test.mht", Format: 7);
Good day community,
Microsoft support have already document this .mht issue and offer a simple solution. I use it to get quick 'highly detail QA and training document in Word format' from PSR.exe recording (also provide in all Windows terminal since Win7). I have a conversion script to do it in batch for my tester/trainer at my compagny. With the right title and the command 'dir /b', it also build a table of content to help research for newly employés :
Ref : https://support.microsoft.com/en-us/topic/the-confirmconversions-property-in-macro-changes-the-confirm-conversion-at-open-option-in-word-6f16c1db-4cb8-2727-dc4f-fdf6ef112ff5
Sub MyDocumentOpenMacro()
Dim x As Integer
' Set x equal to the current setting of the Confirm conversion at Open
' option before opening your file.
x = Application.Options.ConfirmConversions
' Open your file.
Documents.Open "C:\My Documents\Address.txt", ConfirmConversions:=False
' Use a conditional statement to set the Confirm conversion at Open
' option back to its setting (value of x) before opening your file.
If x = "0" Then
Application.Options.ConfirmConversions = False
Else
Application.Options.ConfirmConversions = True
End If
End Sub
I have a macro that asks the user to choose an excel file and then outputs two text files based on the data.
I am looking for a way to just drop the excel file onto the macro file and have it process without the need for opening the macro file, a command button, an open file dialog, etc. I would like to drop the file on the other file and just have the two text files output.
I saw something that looked promising using a VBS file, but was unable to get it to work.
Here's the bare bones of what you need to do:
Wscript.echo "Begin..." 'just letting you know it's working
Set objArgs = Wscript.Arguments 'capture arguments; arg 0 is the name of the dropped file
Wscript.echo "The file name you dropped is:" & objArgs(0)
'DO STUFF TO THE FILE HERE
Wscript.echo "...Finished" 'all done
Save this to a file with a "vbs" extension.
Drag and drop a file onto it.
If your Windows file associations are properly setup,
you'll see this output a message for each of the wscript.echo
lines.
I am trying to tie together a filemaker script that will export PDFs to a temporary space and use and apple script to print them.
I was able to cull together info from this and some other boards to create an applescript that will print the PDFs using Acrobat from a folder.
I have already created a script that finds the Related attachments and exports them to the desktop.
What I'm having trouble with is merging the two.
I need to export the PDF to a folder or temporary place and trigger the apple script to initiate the printing...
This great Suggestion was provided by Chuck of chivalrysoftware.com/…...
Calculate the location to export by appending the filename to Get( TemporaryPath ).
Export the container field contents to FileMaker to that path.
Save the path to a global field in FileMaker
Use an embedded AppleScript to access the global field path
Use AppleScript to open the file in Preview and print it
This is my apple script:
set myFolder to (path to desktop folder as text) & "Print:"
set myfiles to list folder myFolder without invisibles
repeat with myfile in myfiles
set mycurrentfile to ((myFolder as string) & (myfile as string)) as string
batchprint(mycurrentfile)
end repeat
on batchprint(mycurrentfile)
tell application "Adobe Acrobat Pro"
activate -- bring up acrobat
open alias mycurrentfile -- acrobat opens that new file
tell application "System Events"
tell process "Acrobat"
click menu item "Print..." of menu 1 of menu bar item "File"¬
of menu bar 1
click button "Print" of window "Print"
tell application "System Events"
tell process "Acrobat"
click menu item "Close" of menu 1 of menu bar item "File"¬
of menu bar 1
end tell
end tell
end tell
end tell
end tell
tell application "Finder" -- to move the printed file out
set x to ((path to desktop folder as text) & "Printed PDFs:")
if alias x exists then
beep
else
make new folder at the desktop with properties {name:"Printed PDFs"}
end if
move alias mycurrentfile to folder "Printed PDFs"
end tell
end batchprint
My Filemaker script is:
Go to Related Record[
Show only related records; From table: 'Attachments";
Using layout: "Attachements Report' (Attachments); New window
]
Enter Find Mode
Constrain Found Set [Restore]
Sort Records [Restore; No dialog]
# After finding the related attachments and constraining them to the specific type
# we rename and export them to the desktop
Go to Record/Request/Page [First]
Loop
Set Variable [$Path; Value:
Get ( DesktopPath ) & Attachments::Record number & "-"
& Attachment Type List 2::Prefix_z & Lien::Lien_ID_z1]
Export Field Contents [Attachments::file_c; $Path]
Go to Record/Request/Page [Next: Exit after last]
End Loop
Close Window [Current Window]
First of all, the FileMaker part. Create a global text field in one of your tables. It looks like the Attachments table would be the best place for it. I'll call it g_applescript_parameter for this.
Now we're going to use your $Path variable, which given the calc you've provided should be something like /Aslan/Users/chuck/Desktop/1234-ABC4321. I'd recommend appending a .pdf to the end of it since you'll be exporting PDF files. This may help later.
Also, I would recommend that you use Get( TemporaryPath ) instead of Get( DesktopPath ). Anything you place in the temporary folder will be automatically deleted when you quit FileMaker, which means you don't have to write anything to clean up the desktop folder later and you don't have to manually trash them either. Let FileMaker do that work for you. :)
Regardless, FileMaker uses a path of the form filemac:/volumeName/directoryName/fileName (see the notes in the Specify output file dialog box for the Export Field Contents script step). So you should also prepend filemac: to the beginning of your path variable.
All told, your $Path should be set to something like this:
"filemac:" & Get( DesktopPath ) & Attachments::Record number & "-" &
Attachment Type List 2::Prefix_z & Lien::Lien_ID_z1 & ".pdf"
So your export path for FileMaker should work better now. But AppleScript requires a different format for the path to the same file. Given the above, AppleScript's version should be something like /Users/chuck/Desktop/1234-ABC4321.pdf. In other words, everything after the drive name. Fortunately FileMaker can get the drive name with the Get( SystemDrive ) function. For me that function returns /Aslan/. So if we take the $Path variable as defined above and remove filemac: and the name of the drive as defined by Get( SystemDrive ) and add an extra slash at the beginning, that would convert our FileMaker path into an AppleScript path:
"/" & Substitute( $Path; "filemac:" & Get( SystemDrive ); "" )
Use Set Variable to create an $ASPath variable and set it to the above.
Now within your loop store the contents of the $ASPath variable within that global text field:
Loop
Set Variable[ $Path; …]
Set Variable[ $ASPath; …]
Set Field[Attachments::g_applescript_parameter; $ASPath)
Export Field Contents[Attachments::file_c; $Path]
Go to Record/Request/Page[Next; Exit after last]
End Loop
Now AppleScript can extract that information. I'm assuming that given an accurate file being passed to the batchprint function, batchprint will work, so keep that, but remove everything before it and use something like this:
set _pdf_path to contents of cell "g_applescript_parameter" of current layout
batchprint(_pdf_path)
on batchprint(mycurrentfile)
...
end batchprint
Add a Perform AppleScript step after the Export Field Contents step and place the above code in it.
Note that the first line of the above AppleScript will only work as written from within FileMaker. If you're testing this outside of FileMaker in, for example, Script Editor, then you'll need to make that first line read
tell applicaiton "FileMaker" to set _pdf_path ...
You don't need to do this within the Perform AppleScript script step because by default commands are sent to the enclosing FileMaker application.
I'm trying to pull some data from a large PDF file in VB.Net I found the following code online, but it's not helping:
Sub PrintPDF (strPDFFileName as string)
Dim sAdobeReader as String
'This is the full path to the Adobe Reader or Acrobat application on your computer
sAdobeReader = "C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe"
RetVal = Shell(sAdobeReader & "/P" & Chr(34) & sStrPDFFileName & Chr(34), 0)
End Sub
I'm really lost. Any ideas?
/P will just display load the file and display the Print dialog - dead end.
You will probably need a library of some sort to get to the contents of the PDF.
If the file has a very simple structure you maybe able to extract the data just by reading the bytes. See if you can open it with a file like Notepad++ and see the contents.
BTW VS2010 has several editors for looking at/editing files:
File, Open File... pick the file then use the dropdown on the Open button.