I'm having a compiler error whilst trying to navigate to the path of an external script, this is because I have a period in my username. Does anyone know the proper syntax to get around this in AppleScript?
This is the code I'm using to set the path name as a string:
set thePropertyScriptPath to (path to /Users/firstname.lastname/Desktop) & "Properties.scpt"
Does it need to be in there and not just path to desktop?
set thePropertyScriptPath to path to desktop folder as text
set thePropertyScriptPath to (thePropertyScriptPath & "Properties.scpt") as string
Related
I am trying to create a text file that stores a folder path. This text file is then referenced via a vba sub. The path I want to use is something like:
"C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Templates"
This works fine in the sub but I've tried all kinds of variations in the text file but none of them get recognised and trigger error 52 - bad file.
Is there a way to make this work? I'm trying to allow people to set a different file path without needing to modify the code.
If you are trying to provide a path to the folder where user templates are stored then you could try
ActiveDocument.AttachedTemplate.Path
as an alternative (returns the path to the folder where the current template is stored for the user).
Otherwise store the path template as something like
"C:\Users\###UserName###\AppData\Roaming\Microsoft\Templates"
Which gives you a single string to retrieve. Then you can use the VBA Replace function to change the ###UserName### to the value of Environ("UserName)"
my_user_path = replace(my_path_template, Environ$("UserName"))
You might also want to explore using either a CustomDocumentProperty, or a Variables, to store your path template as this keeps the path template string as part of the Document or Template and not in a separate file.
I use following code to run an install file from c: drive.But it throws "Invalid Procedure call or Argument" error.I have tried "eval" to regularize the string ,but it didn't work.
dim BookName
dim Tmonth
dim Trimyear
BookName="Name of a book"
Tmonth="02"
Trimyear="15"
Installfile = "Install " &BookName&" ("&Tmonth&"-"&Trimyear&").msi"
SystemUtil.Run Installfile,"","C:\TitleInstall"
Hey thanks for the intrest. I have checked it with hard coded values, it worked fine. The issue only appears when the value changes dinamically. Please check it with any application on your system and try to assign the value dinamically.
If it works for hardcoded value, it will work for dynamic values as well. Just make sure that the dynamic value you generate in variable Installfile, the same file name is present in your "C:\TitleInstall" folder
As per your above code there should be a file named "Install Name of a book (02-15).msi". Is there any file named like that in your folder?
Just put that Installfile variable in msgbox just above the SystemUtil.Run and verify that file name which comes in msgbox is present in your folder or not.
Also try removing the blank string parameter from your run command(Unless you actually want to pass blank string as parameter) i.e
Change
SystemUtil.Run Installfile,"","C:\TitleInstall"
to
SystemUtil.Run Installfile,,"C:\TitleInstall"
myInstallerPath= "Inataller - Copy.msi"
SystemUtil.Run myInstallerPath , "\q" , "C:\InstallerDir"
The Above worked for me, please note that "\q" is to install an app with out user interaction and does not have any specific implications. SystemUtil.Run is basically your Command window. Launch CMD window, and enter the file path u are trying to execute, to be sure that is valid. (You may want to give the file path within double quotes)
Another option is to give the installer path straight away.. like this..
myInstallerPath= "C:\InstallerDir\Inataller - Copy.msi"
SystemUtil.Run myInstallerPath , "\q"
I am very new to using Automator and Applescript.
I would like to use Automator and AppleScript to detect PDF files that are downloaded to the "Downloads" folder and opens a display dialog that allows me to select the file path and move the file. So far, what I have (which isn't right) is something like:
set question to display dialog "Save fileName in..." buttons {"Figuring Relation", "Iconoclasm", "Elsewhere"} default button 3
set answer to button returned of question
if answer is equal to "Figuring Relation" then
tell application "Finder" to move fileName to POSIX file "/Users/mac/Documents/College/Junior/Fall/Art 347 - Figuring Relation"
I want the "Figuring Relation" and "Iconoclasm" buttons to change the file path to a designated file path (I don't want to browse for it), and the "Elsewhere" button to open a Finder window where I can select/browse the path.
If possible, I'm also looking to add the date to the beginning of the file name as "mm-dd_filename".
I am not sure of how to translate the Automator Input to Applescript, or how to include the filename in the display dialog text. Thank you so much for any help.
Here is an example using just applescript. In my example, it assumes you're selecting the file you're wanting to move, but you could easily add something for the script to "Find" all files ending with ".pdf" if you wanted to and then loop through the results.
on run
try
set thisFile to choose file
tell application "Finder" to set currentName to thisFile's name
-- Setting variables for the destinations to be used later
set FiguringRelationPath to (path to documents folder) & "College:Junior:Fall:Art 347 - Figuring Relation:" as string
set IconoclasmPath to (path to documents folder) & "Iconoclasm:" as string
-- Ask the user
set answer to button returned of (display dialog "Save \"" & currentName & "\" in..." buttons {"Figuring Relation", "Iconoclasm", "Elsewhere"} default button 3)
-- Set the destination variable based on the users response to the dialog
if answer is equal to "Figuring Relation" then
set destination to FiguringRelationPath
else if answer is equal to "Iconoclasm" then
set destination to IconoclasmPath
else
set destination to choose folder with prompt "Please select the destination folder" as string
end if
-- Test that the destination directory exists, if not post the error
try
set destination to destination as alias
on error
error ("Destination path " & destination as string) & " doesn't appear to exist"
end try
-- Rename the file with the date prefix
set tDatePrefix to (do shell script "date '+%m-%d'") & "_" as string
tell application "Finder" to set x's name to tDatePrefix & x's name as string
-- Move the file
tell application "Finder" to move thisFile to destination
on error err
activate
display dialog "Error: " & err buttons {"OK"} default button 1
end try
end run
I'm trying to open a local html using Safari with the following script:
on run
set myPath to (path to me) as text
set myFolderPath to POSIX file (do shell script "dirname " & POSIX path of quoted form of myPath) & ":" as string
set _thispath to myFolderPath & "data:Default.html"
tell application "Safari"
activate
open (_thispath)
end tell
end run
However, the file is trying to open with an apendix of file:/// (an extra slash)
Anyone have any solution to this?
The extra slash is not your problem. First you want to get the "quoted form of the posix path" not the "posix path of the quoted form". That's causing you problems. Plus you aren't converting things to text properly. Anyway, try it this way...
set myPath to path to me
set myFolderPath to POSIX file (do shell script "dirname " & quoted form of POSIX path of myPath)
set _thispath to (myFolderPath as text) & ":data:Default.html"
tell application "Safari"
activate
open (_thispath)
end tell
In general,
Using VBA, how do I determine where the Current users Application Data folder is?
The FileSystemObjects special folders only knows about 3 folders
WindowsFolder
SystemFolder
TemporaryFolder
Specifically, I need a Word Macro to copy a file to the a folder under the Application Data folder.
e.g. In VB.Net I can use My.Computer.FileSystem.SpecialDirectories.CurrentUserApplicationData to do this
You can use Environ("AppData") to get this path. Environ will pull any system variable, which can be found by using the set command at the DOS prompt.
Using advapi32.dll, you can get the USERPROFILE via
Environ("USERPROFILE")
Connect this with the "Application Data" directory (which has a standard, specific name) to get what you want
CStr(Environ("USERPROFILE") & "\Application Data")
For more information, check out MSDN