Error on zipping folders in applescript - zip

I'm trying to develop an automated script to zip up folders but I keep getting the following error:
error "Finder got an error:
zip error: Nothing to do! (/Users/dam/Desktop/Design/_TEST/basefolder/Fonts.zip)" number 12
Been scouring the forums and not quite hitting the mark. Any help for a noob would be appreciated. Thanks!
tell application "Finder"
set projFonts to (choose folder with prompt "Please select font folder.")
set fontPath to quoted form of POSIX path of projFonts
set zipName to the name of projFonts
set theFolder to POSIX path of (container of projFonts as alias)
set zipFile to the quoted form of (theFolder & zipName)
do shell script "zip -j " & zipFile & " " & fontPath
end tell

I think this is what you want, although the question lacks details.
set theItem to (choose folder)
tell application "Finder" to set {fileName, theFolder} to {theItem's name, (theItem's container as text)'s POSIX path}
do shell script "zip -rj " & (theFolder & fileName & ".zip")'s quoted form & space & theItem's POSIX path's quoted form

Related

Change desktop app icons on mac, programatically. 2019

Is there a way to change icons on desktop apps for macbooks, that replicates the same action that happens when you copy / paste icons in the finder window? Either through the terminal, node.js or anything ? I have so far tried:
1) Through the terminal, deleting and replacing the icons themselves, I don't like this because it removes the original icon completely and does not work on every app.
2) Through node.js and terminal, creating an icon? file, however this did not work on every program either, and I had trouble with permission access. If anyone have a solution for this I'd like to hear it.
3) With applescript, this worked but looping through multiple icons at once was too much for it.
I've been searching about this for days, but the information is either very limited or outdated. I would appreciate any help!
To change the icon of an application, I use shell script with applescript.
The goal is to change "Icon file" in the application info.plist and copy the icon (file) in the resources of the application. "application".app/Contents/Resources/ " .
All done in a droplet, on which I drag the desired icon, after opens a window to choose the application whose icon must be changed.
With plutil I convert the file info.plist to xml1 (which I save under ".app/ Contents/infoo.plist" to avoid any problem and find the original). To change the value "Icon file", I use "/usr/libexec/PlistBuddy " with " -c Set: "
to see the change, you have to launch the application (whose icon has been changed), in the dock you have to see the new icon (if the dock option is active)
Below the droplet script
global testdir
on open draggedItems
repeat with currentItem in draggedItems
set icon_image_file_string to POSIX path of (draggedItems)
set {name:Nm, name extension:Ex} to info for POSIX file icon_image_file_string
set Nm to do shell script "echo " & Nm & " | sed 's#." & Ex & "##'"
set testdir to POSIX path of (choose file of type {"APPL"} with prompt "Choisissez l'Application pour changer son icone :")
set {name:Nmm, name extension:Ex} to info for POSIX file testdir
do shell script "plutil -convert xml1 " & quoted form of (testdir & "Contents/Info.plist ") & " | cat " & quoted form of (testdir & "Contents/Info.plist") & " >" & quoted form of (testdir & "Contents/Infoo.plist")
try
do shell script "cp -f " & quoted form of icon_image_file_string & " " & quoted form of (testdir & "Contents/Resources/")
end try
try
set icon_image_file to do shell script "/usr/libexec/PlistBuddy " & quoted form of (testdir & "Contents/Info.plist") & " -c \"Set:CFBundleIconFile " & Nm & "\""
end try
end repeat
end open

VBA to run shell command but to run from different directory

I have code as follows:
ChDir (ActiveWorkbook.Path)
ShellString = "cmd.exe /k cpdf -split " + Chr(34) + ".\" + Replace(File, ".csv", ".pdf") + Chr(34) + " -o temp/x_%%%.pdf"
Shell ShellString, vbNormalFocus
When I run the code, it does nothing, because it can't find cpdf.exe.
Cpdf.exe exists in the same path as my Active Workbook.
The ChDir command did not do the trick.
When I run the code, I get
'cpdf' is not recognized as an internal command....
And I am left at the following prompt:
C:\Users\ksmith\Documents
This tells me that the command was trying to run from that folder, and that is why it failed.
How do I run Shell from Desired folder in VBA?
ChDir doesn't seem to do the trick, as some people had suggested...
The ChDir command only changes the "current" directory on the drive specified, but does not affect which drive is currently "current".
So, if
your computer has a "C" drive on which the "current" directory is "C:\Users\ksmith\Documents", and
you also have an "L" drive on which the "current" directory is "L:\abc\def",
and
the directory containing your workbook is "L:\Temp1\Temp2"
then executing
ChDir ActiveWorkbook.Path
will change the "current" directory of the "L" drive to be "L:\Temp1\Temp2", but the "current" drive will continue to be "C" and the C drive's "current" directory will continue to be "C:\Users\ksmith\Documents".
You therefore need to also change the "current" drive. Providing you have a mapped drive (i.e. it won't work with a UNC specified drive) you can do this by using:
ChDrive ActiveWorkbook.Path
ChDir ActiveWorkbook.Path

Shell command on Excel with long path name don't work

I have a batch file run.bat in a network folder "L:\Common Data\myfile" and i want to execute it from an Excel's macro.
Googling around I found these sintax:
Call Shell(Environ$("COMSPEC") & " /k L:\Common Data\myfile\run.bat", vbNormalFocus)
but it fails because it reads only "L:\Common".
I tryed many suggestion found on Internet but no one succeeded.
Someone have a solution?
Path names with spaces have to be wrapped in quotes.
Call Shell(Environ$("COMSPEC") & " /k ""L:\Common Data\myfile\run.bat""", vbNormalFocus)

Query Parameters in Express being extracted?

I'm writing an API in Node.JS for an AppleScript application. The AppleScript application runs curl in a shell script in this form:
do shell script ("cd " & quoted form of myDir & "
curl http://localhost:5000/server.properties?some-value=true&next-value=something%20else&[...] -O")
It's intended to download a file called server.properties into the directory myDir with content based on the specified parameters, but for some reason when Express receives the request, it displays only this when I run console.log(res.originalUrl):
/server.properties?some-value=true
And it treats the request as if none of the other parameters are specified. Can anyone tell me what I'm doing wrong, or how to figure out where it's going wrong?
EDIT It turns out to be the way I ran the shell script. The URL needs to be quoted so that the & doesn't act as an operator in the shell script.
My solution was the following:
do shell script ("cd " & quoted form of myDir & "
curl " & quoted form of (myUrl & myQuery) & " -O")
Where myUrl is set to "http://localhost:5000/server.properties" and myQuery is set to "?some-value=true&next-value=something%20else&[...]".

use winrar command line to create zip archives

I'm using the following winrar command line to create zip archives:
rar.exe a -df -ep -ag[yyyyMMddhhmmss] -ms[txt] C:\MyZipFile.zip C:\tmp\MyFiles*.txt
The archives created are in RAR format instead of ZIP. Is there a way to create regular ZIP and not RAR archives?
Make certain you are using WinRAR.exe and not Rar.exe.
If you are using the command line to do this make sure you type:
winrar a -afzip c:\test.zip c:\test.csv
not:
a -afzip c:\test.zip c:\test.csv
It works for me. I also got it to work in SSIS.
WinRAR has a detailed description of its command line syntax in its help files (WinRAR Help), chapter "Command line syntax".
All the commands such as "a" (add to an archive), "d" (delete from an archive), "e" (extract from an archive ignoring paths) and switches such as "-af" (specify whether to create a rar or a zip file), "-ad" (append archive name to destination path) or "-p" (encrypt the archive using password protection) are listed there.
There are quite a lot of options. I recommend reading the command line syntax rules when working with WinRAR via command lines.
In order to trigger WinRAR zip-packaging from within a MS Access database application, I use in the VBA code for example
Shell c:\Programme\WinRAR\winrar.exe a -afzip -p <AnyPasswordYouLike> "e:\MyStuff\TargetFolder\Output.zip" "e:\MyStuff\SourceFolder\Input.docx"
Of course, the file paths and names are ususally entered via variables, e.g. like
Dim strWinrarCommandline As String
'... and the other variables as well declared in advance, of course...
strWinrarCommandline = strWinrarPathAndSwitches & "-p" & strPassword & " " & Chr(34) & strOutputFullName & Chr(34) & " " & Chr(34) & strInputFullName & Chr(34)
'And then call Winrar simply by:
Shell strWinrarCommandline
So rar.exe is currently unable to create zip files by itself only by calling in the Windows version it is possible.

Resources