Editing .doc document using AppleScript - batch-file

I am trying to batch convert some .doc files to .pdf
I am pretty sure I've got the concept right, I just do not know how to reference the format to change the file format when I "Save As"
set F to choose folder
tell application "Finder"
set P to (files of entire contents of F)
repeat with I from 1 to number of items in P
set this_item to item I of P as alias
tell application "Microsoft Word"
activate
open this_item
save as active document file format format PDF
close window 1
end tell
end repeat
end tell
Thanks

A little google searching would have turned up this...
which is basically the whole script you're trying to write.

Related

Quicktime Error opening random files using simple apple script

I'm getting the following error:
"The file isn’t compatible with QuickTime Player."
When using this script:
tell application "Finder"
set random_file to some file of entire contents of folder "Movies" of home
open result
end tell
However, I am able to open the file from the finder manually and once I do the script works on just that file. The problem is I have thousands of files and don't want to open each one manually for the script to work again. Have not had this problem with the script in the past.
There are two ways I can think of to approach modifying your script:
Stick with Finder's open command but invoke it fully with its using parameter, which accepts an application file that informs Finder of the application that will be used to open the file. It may sound superfluous given it already tries to open it in QuickTime, and we're not trying to change that, but it's not unwise to see if it does confer a difference in behaviour:
tell application id "com.apple.finder"
tell the folder (path to movies folder) to tell (the ¬
a reference to entire contents) to tell (the ¬
some document file as alias) to set f to it
open f using application file id "com.apple.QuickTimePlayerX"
end tell
Grab the file as you like (really, you ought to be using System Events for this, not Finder, but I'll go with what you had), but then use the open handler of the specific application to open the file:
tell application id "com.apple.finder" to tell the folder (path to movies folder) ¬
to tell (a reference to the entire contents) to tell (some document file) ¬
as alias to set f to it
tell application id "com.apple.QuickTimePlayerX"
activate
open f
end tell
NB. I'm using Monterey, in which both of these two above propositions work appropriately. This doesn't necessarily infer that it will do so in Big Sur, but if they do not, it's worth checking the various app permissions under the different Security & Privacy headings of System Preferences.

Q: Applescript - not passing all files in folder

I have a question, basically i've wrote "application" in Applescript, and something is quite suspisious.
tell application "Finder"
activate
set theXMLFolder to choose folder with prompt "ok"
set numberOfFiles to count of (files in folder theXMLFolder)
repeat with a from 1 to numberOfFiles
set theXMLFile to item a of theXMLFolder
if name extension of theXMLFile is in validExtensions then
my resetVariables()
my importXMLFolder(theXMLFile as string) -- import and read XML file
my writeToExcel() -- convert XML to Excel file
end if
end repeat
end tell
This is the way how i'm prompting for XML files inside folder. Problem is that when in the folder there are only XML files it works perfect, but in the moment there will be some other files sometimes it doesn't read them all, for ex. it will only find 7 out of 9 files. Is there any way to make it see always and all files?
Thank you
This works for me on the latest version of Sierra
With this code you can bypass the whole “conditional” part of your code
property nameExtension : "xml"
set theXMLFolder to choose folder with prompt "ok"
tell application "Finder"
set theFiles to files of theXMLFolder whose name extension is nameExtension
repeat with i from 1 to number of items in theFiles
set theXMLFile to item i of theFiles
my resetVariables()
my importXMLFolder(theXMLFile as string)
my writeToExcel()
end repeat
end tell
The following example AppleScript code only acts on files having the name extension set in validExtensions, e.g. xml, and will act upon every xml file based on what's in the repeat loop, i.e. -- # Do something.:
set validExtensions to {"xml"}
tell application "Finder"
set theXMLFolder to choose folder with prompt "Select the folder containing the xml files:"
repeat with i from 1 to (count of files in folder theXMLFolder)
set theXMLFile to item i of theXMLFolder
if name extension of theXMLFile is in validExtensions then
-- # Do something.
log (get name of item i of folder theXMLFolder)
end if
end repeat
end tell

How to add text documents into a file using Batch

Is it possible to create a text file and place it in an existing file using Batch? What I mean is when I type echo %input%>document.txt it obviously saves it as a text document, but what I want to happen is for it to automatically place that text document into an existing file that I have previously created. Do I have to call the folder name? I'm honestly lost on how to do this. Any help would be great!
Instead of doing
echo %input%>document.txt
You can specify the entire path of the text document
echo %input%>C:\path\to\document.txt
Obviously you need to change the path to be whatever you want.

Colon(:) and number in filename in Visio

I have done some search but nothing same up really.
I have got a visio file, and when I double click and open it up, it open 5 copies of the document in same window and names them as format of filename:1, filename:2 and so on. they seem identical.
any idea Why this happens?
thanks for the help.
Regards
Mesut
All the windows are showing the same file. When this file was saved there were multiple windows open. This workspace is saved with the file. When you reopen the file the same views are opened. To stop this close all but one window and then save the file.

Copy A File In AppleScript

I have the code below to set a variable in Applescript for the path to the iTunes Music Folder:
set username to text returned of (display dialog "RingtoneDude" default answer "Enter your path to your iTunes Ringtones folder here. e.g. /Users/David/Music/iTunes/iTunes Music/Ringtones" buttons {"Confirm", "Cancel"} default button 1)
And then I have the code to call the variable username to copy a file
tell application "Finder"
copy file theCopy to username
end tell
but the file theCopy which is on the desktop (theCopy is a variable) does not move to the folder.
Please help.
I believe you've misunderstood the copy command. The copy command is used for transferring the contents of one variable into another variable. What you need to use is the duplicate command, which is used for copying files to a specified location. Its syntax is as follows:
duplicate [alias] to [alias]
[replacing boolean] --If true, replaces files in the destination with the same name
Having said that, your new code, in conjunction with Uriah Carpenter's answer, should look something like this:
set myRingtoneFolder to choose folder with prompt "Select your iTunes Ringtone folder:"
tell application "Finder" to duplicate theCopy to myRingtoneFolder
I would suggest you use choose folder which returns an alias.
To make some text into an alias object use set myAliasPath to myTextPath as alias.
For more detailed information see Aliases and Files in the AppleScript documentation.

Resources