How to Zip folder with AppleScript-objc? - applescript-objc

I'm generating a few Logs on the system, and then copying it to /tmp/MyFolder, and then
I move the folder to the desktop, I'm trying to compact it before you move on, but I don't know how to do it, I have tried the following:
tell application "Finder"
set theItem to "/tmp/MyFolder" as alias
set itemPath to quoted form of POSIX path of theItem
set fileName to name of theItem
set theFolder to POSIX path of (container of theItem as alias)
set zipFile to quoted form of (theFolder & fileName & ".zip")
do shell script "zip -r " & zipFile & " " & itemPath
end tell

While this isn't an AppleScript-ObjC script, I'm posting the corrected version of your own script so that it functions to do as you described:
tell application "System Events"
set itemPath to "/tmp/MyFolder"
set theItem to item itemPath
set fileName to quoted form of (get name of theItem)
set theFolder to POSIX path of (container of theItem)
set zipFile to fileName & ".zip"
end tell
do shell script "cd " & quoted form of theFolder & ¬
"; zip -r " & zipFile & space & fileName & ¬
"; mv " & zipFile & space & "~/Desktop/"
Trying to avoid using Finder for file system operations. It sounds counter-intuitive, but it's not well-suited for it. Use System Events, which has—among many other benefits—the ability to handle posix paths.
The script now zips the folder and its containing items into an archive at /tmp/MyFolder.zip, then moves this archive to the desktop.

Related

select some of (EOF) extension files in specific folder based on part of filenames in text file :explained in image file with connected arrow

I want to Select files in specific folder based on part of the name of files(date)
so:
1-first: (in names.csv) extract part of file name(date) :find all("1SDV_(\d+)T", name)
2-second: (in name of files in specific folder) extract part of file name(date):
find all ("OPOD__(\d+)T", name)
of all (EOF) extension file names in specific folder
3-third: relate extraction: as image that I attached (red connected arrow)
my code is not complete please help me to complete it
enter code here
import OS
import re
# open the file, make a list of all filenames, close the file
with open('names.csv') as name file:
# use .strip() to remove trailing whitespace and line breaks
names= [line strip() for line in name file]
for name in names:
res = re find all ("1SDV_(\d+)T", name)
if not res: continue
print res[0]
# You can append the result to a list
# Find all ("OPOD__(\d+)T")
# how can I relate (EOF) extension files name to res like image file I
attached
# move the selected (EOF) extension file
OS rename(OS path join('path', (EOF) file extension folder),
'/path/to/somewhere/else')
break
csv or text file is like this:
S1A_IW_SLC__1SDV_20190826T022837_20190826T022904_028734_0340DD_654D-SLC
S1A_IW_SLC__1SDV_20190919T022838_20190919T022905_029084_034D09_0129-SLC
S1A_IW_SLC__1SDV_20191013T022839_20191013T022906_029434_03590E_A824-SLC
S1A_IW_SLC__1SDV_20191106T022839_20191106T022906_029784_036538_06CC-SLC
S1A_IW_SLC__1SDV_20191130T022838_20191130T022905_030134_037166_4019-SLC
S1A_IW_SLC__1SDV_20191224T022837_20191224T022904_030484_037D7B_0FC4-SLC
S1A_IW_SLC__1SDV_20210217T062720_20210217T062747_036626_044D90_4570-SLC
.
.
.
And (EOF) extension files in specific folder are like :
S1A_OPER_AUX_POEORB_OPOD_20190915T120743_V20190825T225942_20190827T005942.EOF
S1A_OPER_AUX_POEORB_OPOD_20190916T120658_V20190826T225942_20190828T005942.EOF
S1A_OPER_AUX_POEORB_OPOD_20190917T120653_V20190827T225942_20190829T005942.EOF

I am writing a DXL script to print a modulename with path using a function . I need to remove if the directory has remote in that path

Below module is forming a directory from a path
Checkmodules("Cus", "projectname".cfg", ".*(Cus|Cer Requirements|Cer Speci|ASM|/ASM24e|Specs).*");
The above line forms below folder directory, so I need to modify it when the directory has remote in the path its should be removed entire directory.
Output path
Cus/spec/cer/
cus/val_remote/value - this also needs to be removed
Cus/sys/remote ---- to be removed entire path
You can do a replace (to an empty string) with the following regex combined with the flag g (global=all occurrences) and m (multiline)
^.*remote.*$
In JavaScript this would be :
outputPath.replace(/^.*remote.*$/gm, '')

Error using VBScript in BGInfo File not found error

I'm an amateur VB scripter.
I am creating a script to output the ID.
The file contains the line "ad.annnet.id = 564654068". It is necessary to output "ID: 564654068"
With New RegExp
.Pattern = "\nID=(\d+)"
Echo .Execute(CreateObject("Scripting.FileSystemObject").OpenTextFile("this.conf").ReadAll)(0).Submatches(0)
End With
There are multiple issues with the script, the actual cause of the "File not found" error is as #craig pointed out in their answer the FileSystemObject can't locate the file "this.conf". This is because the OpenTextFile() method doesn't support relative paths and expects an absolute path to the file whether it is in the same directory as the executing script or not.
You can fix this by calling GetAbsolutePathName() and passing in the filename.
From Official Documentation - GetAbsolutePathName Method
Assuming the current directory is c:\mydocuments\reports, the following table illustrates the behaviour of the GetAbsolutePathName method.
pathspec (JScript)
pathspec (VBScript)
Returned path
"c:"
"c:"
"c:\mydocuments\reports"
"c:.."
"c:.."
"c:\mydocuments"
"c:\"
"c:"
"c:"
"c:.\may97"
"c:.\may97"
"c:\mydocuments\reports*.*\may97"
"region1"
"region1"
"c:\mydocuments\reports\region1"
"c:\..\..\mydocuments"
"c:....\mydocuments"
"c:\mydocuments"
Something like this should work;
'Read the file from the current directory (can be different from the directory executing the script, check the execution).
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim filename: filename = "this.conf"
Dim filepath: filepath = fso.GetAbsolutePathName(filename)
Dim filecontent: filecontent = fso.OpenTextFile(filepath).ReadAll
Update: It appears you can use path modifiers in OpenTextFile() after all (thank you #LesFerch), so this should also work;
'Read the file from the current directory (can be different from the directory executing the script, check the execution).
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim filename: filename = ".\this.conf" '.\ denotes the current directory
Dim filecontent: filecontent = fso.OpenTextFile(filename).ReadAll
Another issue is the current RegExp pattern will not match what you are expecting, would recommend using something like Regular Expressions 101 to test your regular expressions first.
In bginfo, click Custom, New, enter ID for the identifier, Check the VB Script file radio button, and then click Browse to select a VBScript file you have saved with the code below. Then add the "ID" item to the bginfo display area. Note: The "file not found" error is resolved by using the AppData environment variable to reference the AnyDesk data file.
Const ForReading = 1
Set oWSH = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
AppData = oWSH.ExpandEnvironmentStrings("%APPDATA%")
DataFile = AppData & "\AnyDesk\system.conf"
Set oFile = oFSO.OpenTextFile(DataFile,ForReading)
Do Until oFile.AtEndOfStream
Line = oFile.ReadLine
If InStr(Line,"ad.anynet.id") Then ID = Split(Line,"=")(1)
Loop
oFile.Close
Echo ID
Please note that the data is returned to bginfo via one or more Echo statements. If testing this script outside of bginfo, change Echo to WScript.Echo.
You will never get the value/display that you're looking for if the output is
File Not Found
The regexp is meaningless until the path to the file is specified. As it stands, the "this.conf" file must be in the same location as the script itself - and from the error, I'm assuming that's not the case.

boost::program_options space in config file

I want to set options to my parser program via simple config file parsed by boost::program_options. I want to set prefixmiddle to (single space).
I already tried that options:
prefixmiddle=
prefixmiddle=" " # Equals to `" "`
prefixmiddle = " " # Same
prefixmiddle =
Is there a way to do it?
P.S. Of course, I can always use "" and remove them, but I wonder if there is another solution.

Applescript Posix files and paths

I am trying to set a script to duplicate a template file to a newly created folder. The file is a variable created from template_name. Unfortunately I am a posix novice and can't seem to get the script to copy the template file to the new folder.
The returned error is
"Can't set "/Volumes/Media/NewFolder" of application "Finder" to file "Volumes/Media/+A3Temp.ptx" of application "Finder"
set temp_name to client_code & " " & brand_name & " " & job_name & " " & job_number & " " & creation_date
set media_folder to "/Volumes/Media/"
set new_folder to media_folder & temp_name
set template_name to ("+" & suite & "Temp.ptx") as string
set session_name to (client_code & " " & brand_name & " " & job_name & " " & creation_date & ".ptx")
set template to (media_folder & template_name)
tell application "Finder"
duplicate POSIX file template to POSIX file new_folder
end tell
I know the error is with these lines
tell application "Finder"
duplicate POSIX file template to POSIX file new_folder
end tell
But i have no clue as how to remedy it. Can anyone help please!?
I got a similar error when I ran this script:
set f to "/usr/share/dict/connectives"
set d to "/private/tmp/"
tell application "Finder"
duplicate POSIX file f to POSIX file d
end tell
Finder got an error: Can’t set POSIX file "/private/tmp/" to POSIX file "/usr/share/dict/connectives".
Either of these worked though:
set f to POSIX file "/usr/share/dict/connectives"
set d to POSIX file "/private/tmp/"
tell application "Finder"
duplicate f to d
end tell
tell application "Finder"
duplicate POSIX file "/usr/share/dict/connectives" to POSIX file "/private/tmp/"
end tell