Pass argument to AppleScriptTask - excel

When I switched to MacOS Mojave, I was no longer able to save an Excel document as a PDF to a specific location using a macro.
I have had to save it to /Library/Group Containers/UBF8T346G9.Office/⁩ and then move it to the Desktop by calling a script stored in /Library/Application Scripts/com.microsoft.Excel/.
This has worked for months. Someone who uses this macro/script combo has all of a sudden been unable to do so. No other user has a problem, some having the same combination of Excel and MacOS (16.29 and 10.14.6 respectively).
When she tries to run the macro, it throws
Invalid procedure call or argument (Error 5)
specifically on the line that calls this script.
There is another script at the beginning of the macro that does not take an argument and is working. I used MsgBox to see what string was being passed to AppleScriptTask, plugged it into the script using Script Editor, and ran it without issue.
Here is the AppleScript:
ExistsFile(sPath)
on ExistsFile(sPath)
set sPath to sPath as POSIX file
tell application "Finder" to set sPath to file sPath
set dest to (path to desktop)
move sPath to dest without replacing
end ExistsFile
Here is the call from the macro:
result = AppleScriptTask("moveToDesktop.scpt", "ExistsFile", sPath & strJobNumber & " Cover Page.pdf")
I tried the following based on what I have seen on other forums:
Set the filename to a variable and passing that to AppleScriptTask
Removing the extension in the script, removing the extension in the folder, and combinations of those two

In MacOS Mojave and newer, you'll need to do the following:
Open System Preferences - Security and Privacy - Privacy Tab - Automation - Excel ~ check off Finder.

Sounds like it could be a permissions error if it fails to run for one user only. This page has all the requirements to run the AppleScriptTask command. Possible solution could be to enable the correct permissions for the script to run using chmod command from terminal. This will provide permission for root and current user. If this doesn't work, double check that all the requirements are met on the user's system.
cd <path to script file>
sudo chmod 755 moveToDesktop.scpt

Its the spaces in the parameters you are passing to the AppleScript. You have at least one one before "Cover Letter.pdf" (and then one between "Cover" and "Letter"), probably in other cells as well that you are using to create the parameter.
I had the same problem as well as it was driving me mad that the AppleScript itself was working fine when feeding it the combined parameter directly.

Related

I am trying to get a shortcut *.pdf file to open using command prompt via vba

I have been attempting various methods of opening a shortcut *.pdf file using command prompt via vba but have had no success yet directly from vba.
If I enter the following in cmd.exe it opens fine:
start "" /max "G:\All Production Drawings\All Production Drawings\Production Drawings\Electronic job card drawing shortcuts\920002300-1.pdf - Shortcut"
I tried the replicating this line of code in vba and had all sorts of problems with the file not either being found or various other errors so I decided to try a different method.
Shell "G:\All Production Drawings\All Production Drawings\Production Drawings\Electronic job card drawing shortcuts\920002300-1.pdf - Shortcut" - this says the file is not found. It is definetly there!
The code below runs with no errors but nothing comes up at all:
Sub opendrawing()
Dim fso As Object
Dim MyFile As String
Set fso = CreateObject("Shell.Application")
MyFile = "G:\All Production Drawings\All Production Drawings\Production Drawings\Electronic job card drawing shortcuts\920002300-1.pdf - Shortcut"
fso.Open (MyFile)
End Sub
If I use either variation of code to open the file directly it works fine but not when I try and open the shortcut. I've been looking about for a while on this one and feel it isn't possible for some reason or another.
Does anyone have any idea on this one please?
Thank you :)

Why does 'shell' opening an executable in a Visual Basic Script sometimes give a 'run time error 5' but not always?

I am playing around with the basics of VBS and have a very simple Visual Basic script which executes a file using shell.
I am using Excel under Windows 10.
Sub Whatever()
Dim Example_One As String
Example_One = "C:\Users\IEUser\python-3.8.0.exe"
Shell Example_One, vbNormalFocus
End Sub
The weird thing is that some files will run (e.g. Python as above) while others e.g. VLC, WinRAR give the error: Run time error 5: Invalid procedure call or argument.
I simply cannot figure out why some .exe files will run and others will not. I thought it might be something to do with how the installation works but ChromeSetup.exe works while VLC.exe does not (even though they both ask "Do you want this app to make changes to your device?" (Python has it's own installer). Double-clicking all files in Windows Explorer runs them as normal (they don't ask for any special rights).

Visual Basic FileCopy error75 after Microsoft Office 2010 updates

Recently a large number of security updates were pushed for Microsoft Office at work. We have an Excel tool with a Visual Basic backbone which worked prior to the updates, and now does not work.
I have done some isolated testing and have found that we see the same 'error 75' when using the FileCopy method on .BAT and .EXE files. Other less 'risky' file types seem to be ok. This is also an issue with the 'Open' command.
Does anybody know of a workaround for this issue when copy/pasting .EXE and .BAT files, or maybe this is a known issue with a certain security update? I have searched everywhere, but the Google is failing me. I am hoping either:
Someone knows which security update is the culprit and I can try
uninstalling it to see if that fixes the issue
There is a different way to copy/open/manipulate .BAT and .EXE files that doesn't violate the new security patch.
Some background:
We are using Microsoft Office Professional Plus 2010 and the tool uses Excel as the interface.
Here is the testing code I am using. I have verified that .TXT and .DAT files run just fine while .EXE and .BAT files cause 'error 75' indicating a permissions error. And before you ask, yes, the file path is correct, I have just omitted my employee identification information.
Sub Macro1()
' Declare variables
Dim Filename, SourcePath, DestPath As String
' Pathname variables
Filename = "test.dat"
SourcePath = "C:\Users\<REDACTED>\Desktop\working_copy\" & Filename
DestPath = "C:\Users\<REDACTED>\Desktop\working_copy\test\" & Filename
' Copy file from Source and paste in Destination
FileCopy SourcePath, DestPath
End Sub
Here is an image with the updates that were installed. The tool worked prior to the 6/14/2017 dump, so anything before can be disregarded.
Sorry for the image, too many to enter them manually, no easy way to copy from the update list:
MS Office 2010 Security Updates
Nothing with the tool or file structure changed. The only thing different is the updates. Also, we tested the same tool with Microsoft Office Home 2016 and it worked without a hitch.
Any and all help will be appreciated. Thanks in advance!
While I never found a real fix for this issue, I did come up with a slightly 'hacky' work-around.
The MS security patch prevented me from copy/pasting .BAT and .EXE files, I but could still save .BAT files.
So, I ended up having my script create a text file called "copyExe.txt" which had a single line:
ECHO F|xcopy <source> <destination>
This was then renamed to be "copyExe.bat" and run.
By creating a .txt file, I circumvented the errors when using the VBA Open function on .BAT files (so I could actually create this new batch file). This batch file has the sole purpose of copy/pasting a .EXE file from one folder to another, which circumvented errors when trying to copy/paste .EXE files.
After the copy/paste script is run, it is deleted.
All-in-all it feels like a very silly solution, but it works and is very non-invasive for the user.

AppleScript Replace File

I'd like to write an AppleScript for replacing three system files with ones I've modified. I'd like to do this with an AppleScript instead of manually replacing them because I'll have to replace three files every time there's an OS X update. Specifically, I'll be replacing stock graphics drivers with ones I've modified to support a graphics card which is connected via Thunderbolt. Is it possible to write an AppleScript for replacing one file with another? I ask because I know that when you replace a file, a dialog pops up with three options, and I don't know how to address that.
You can do this with Finder:
set freshFile to choose file
tell application "Finder"
move freshFile to desktop replacing yes
end tell
All you need to do is work out the source and destination paths to completely automate the script.
Many scripters do not like working with Finder, for a variety of reasons. If you want something that is incredibly fast, you would use the do shell script inside of your AppleScript:
do shell script " mv -f ~/Desktop/ArlandaTilUppsala.pdf ~/Documents/Employ.pdf"

Proper Syntax for revZipAddUncompressedItemWithFile?

I recently found an error in the documentation for revZipAddItemWithData. Now I'm trying to do something similar, but this time using revZipAddUncompressedItemWithFile. I suspect I have a similar problem. I've tried every combination of quotes or no quotes around the arguments, with no luck.
I'm not having trouble with any other handlers reading or writing to the zip archive, just this one.
Any ideas?
command SaveIssue
put field "Archive Path" into tPath
ask file "Save as:" with "someimage.jpg"
put it into tFilePath
set itemDelimiter to slash
put item -1 of tFilePath into tFileName
revZipOpenArchive tPath, "update"
revZipAddUncompressedItemWithFile tPath, tFileName, "tFilePath"
revZipCloseArchive tPath
end SaveIssue
Using LiveCode 6.6.2 stable, Mac OSX 10.9.4
I get it working with no quotes around the arguments;
revZipAddUncompressedItemWithFile tPath, tFileName, tFilePath
However, it doesn't work with an archive that I create by right-clicking a file (on a Mac) and selecting 'Compress ...' (The archive is reported as 'damaged' if I try to open it afterwards!)
It does work with an archive created with LiveCode

Resources