Applescript or Automator to save Mandelbrot image from website progressivly - c

Hello I have recently created a C program for my UNI Computing course that generates a web server at localhost:2020 and sends a bmp file of the Mandelbrot set. If you dont know what that is dont worry, its the url part thats important.
The URL is formatted as follows
http://X_(x coordinate)_(y coordinate)_(Zoom Level).bmp
so
http://localhost:2020/X_-0.15_1.03_56.bmp
returns
x: -0.15
y: 1.03
zoom: 56
My goal here is to have an automated process that can take in an x,y position (in the code is fine) and repetitively load the image from the server, each time with a zoom level increased by .01 and save it to either a folder or preferably load them all into a file to be presented as a video.
Im well aware that this would be easier to do in C and just have it save to the file but my goal is to familiarise myself with applescript/automator or a similar program with tasks like this.
Its designed to be a fun learning experience for myself and I will really appreciate any help I can get thank you.

Something like this may work for part of your task. We are downloading all of the images (at each zoom level) using the unix command line utility "curl". Each image is saved with the name from the url to a folder that you choose. We put this code inside a repeat loop so we can increment the zoom level.
The script shows lots of stuff, particularly how to insert variables directly into an applescript (e.g. hard-coded) and how to get input from the user. It also shows how to run command line utilities from within an applescript (e.g. curl).
So this script should get you started. See if it helps.
-- hard-coded variables
set minZoomLevel to 0
set maxZoomLevel to 10
set zoomIncrement to 0.1
-- get user input variables
set outputFolder to choose folder with prompt "Pick the output folder for the images"
set xDialog to display dialog "Enter the X coordinate" default answer ""
set yDialog to display dialog "Enter the Y coordinate" default answer ""
set posixStyleOutputFolder to POSIX path of outputFolder
set x to text returned of xDialog
set y to text returned of yDialog
set i to minZoomLevel
repeat while i is less than or equal to maxZoomLevel
set fileName to "X_" & x & "_" & y & "_" & (i as text) & ".bmp"
set theURL to "http://localhost:2020/" & fileName
do shell script "curl " & theURL & " -o " & quoted form of (posixStyleOutputFolder & fileName)
set i to i + zoomIncrement
end repeat

Related

Copy New Access client to users

I use a very simple version control whereby I use the "tag" property on the Switchboard to record the version of the database.
On a linked "mastertable" I have a master record that shows the current version. If this is out of sync, then there is code in the switchboard to initiate a simple file copy of the new client version to the user's desktop.
I can't use any EXE type auto-installers to do this, so had to come up with an all Access solution, but having some issues with shell commands and timing that is causing the "auto" part of the installer to be inconsistent.
Below are my codes for the Client and my standalone "Installer" database (which only has one form that opens on startup and initiates the copy code). I use lookup tables for all file locations, but will use strings in my example.
Client.mdb:
strInstaller = "c:\Installer\Installer.mdb"
set obj = CreateObject("access.application") 'previously tried SHELL command
with obj
.visible = true
.userControl = true
.openCurrentDatabase (strInstaller)
end with
application.quit
Simple enough. So the above code just opens my Installer mdb which opens a form and executes the following on open.
Installer.mdb:
strFileName = "ClientDB"
strMaster = "D:\" & strFileName
strClient= dlookup("DBPath", "UserTbl", "LanID = '" & MyID & "'") & "\" & strFileName
if len(dir(strClient)) <> 0 then
kill strClient
end if
filecopy strMaster, strClient
The dlookup in the strClient simply looks up the path where the user opened up the instance of the client mdb. (I record this on every instance).
My issues is that I am not getting consistent results. Sometimes it will copy the file, and sometimes it won't. I've changed it to run from a button on the Installer Form, and it works every time, so I'm guessing it has something to do with timing.
I've tried putting a pause function before the kill command, and that seems to help if I set the pause to 3 or 4 seconds. I originally used Shell to open the Installer, but got rid of it as I heard that it was running concurrently with the installer.mdb code.
I'm thinking it's something obvious, but I've been staring at this for about an hour and can't figure it out. Ideally, I don't want the user to interact with this form using an "Install" button, but would like it to happen in the background. i.e. I want to set the .visible = false at some point.
Can anyone see an issue with this method, or suggest a better method to push out new copies of the client - and I can't use any EXE install programs.
You likely want to use the shell() command. You can use CreateObject, but that feature is NOT available in the runtime. (and worse, it will not work).
The simple trick is ONCE you shell out to the upgrade program, you want to QUIT the main program (since you can’t copy over it while it is running).
The code I use is thus:
strCurrentDir = CurrentProject.Path & "\"
' path to msaccess.exe is determined here
strShellProg = q & SysCmd(acSysCmdAccessDir) & "msaccess.exe" & q & " "
' path to current dir...assume upgrade program in same folder
strShellProg = strShellProg & q & strCurrentDir & "UpGrade.accDE" & q
If Shell(strShellProg, vbNormalFocus) > 0 Then
Application.Quit
Else
MsgBox "Un able to run upgrade", vbCritical, AppName
Application.Quit
End If
In above “q” is = """" (a single double quote).
So you shell out, and then immediate do a application.Quit. The upgrade program should have a “prompt” like “about to upgrade – ok”. That “prompt the user has to hit gives the main application time to quit. I also useally write out the locations to a text file in the above code - but the above steps to shell() is the main takeaway solution here.
As noted, you can use create object, but THEN if you quit the main application, then that variable holding the upgrade program will also go out of scope (or worse, the main application cannot shut down because it is “hosting” an automated copy of the upgrade application by CreateObject.
So you in practical terms don’t want to use createObject, since this means the main program is “hosting” or “holding” a copy of the upgrade program and the main program really can’t quit.

Automatisation, Load .prg file, run it with pre-defined variable

The idea is that in one folder there are two files
test.csv
test.prg
I would like to run with .bat file (or .vbs) the file test.prg with variable "2510".
It will automatically load in Visual Fox Pro (here I do not know how to run script automatically with out physically click the exclamation mark) and visual fox pro should use variable from .bat/.vbs file as 2510.
1) Open test.prg
2) Load VFP
3) Use pre defined variable from .bat/.vbs
4) Run script (automatically)
5) close VFP
Because this is daily jobs, and I'm trying to simplify as much as possible (currently I know only how to simplify by using cmd/.bat and vbs)
If I understood you right, you want to run a prg file with changing parameters and you want to change the parameter in the calling .bat or .vbs file. If it is what you wanted to do, then you could simply have the bat file content like:
cd "c:\My Folder"
"c:\Program Files (x86)\Microsoft Visual Foxpro 9\vfp9.exe" test.prg 2510
and your prg would be run with that parameter. Keep in mind that parameters passed from command line is always of character data type.
However, there is an easier way. The way you do it, you would edit the .BAT file, save it and then doubleclick to execute. You might create a VFP executable instead, in command window (assuming test.prg is in c:\My Folder'):
set default to ('c:\My Folder')
build project MyTest from 'test.prg'
build exe MyTest from 'MyTest.pjx'
and you would have MyTest.exe in that folder. Your BAT file content would then be:
cd "c:\My Folder"
MyTest 2510
It is still to cumbersome. You need to edit the .BAT file, change parameter, save and doubleclick it. Make it much simpler:
In your test.prg, instead of getting a parameter from command line, ask the parameter value and do the process! That totally removes the need for a BAT file. Then you simply create a shortcut on your desktop. Whenever you doubleclick that shortcut, it would ask for the parameter and then do processing with that parameter value and quit. The content of such a test.prg would look like:
_screen.Visible = .T.
LOCAL cInput
cInput = INPUTBOX("What is parameter value?", "Get parameter value", "2510", 5000, '', 'Cancelled')
DO case
CASE m.cInput == ''
? 'Input timed out'
CASE m.cInput == 'Cancelled'
? 'Cancelled'
CASE m.cInput == '0' Or VAL(m.cInput) != 0
Process( VAL(m.cInput) )
OTHERWISE
? 'Parameter is not numeric'
ENDCASE
QUIT
PROCEDURE Process(tnparameter)
? 'Processing with parameter =', m.tnParameter
Endproc
Also, instead of an inputbox() which returns a character value as command line parameters do, you might get the value(s) via a form with their intended types (ie: A datetimepicker on a form getting date).
It is really unclear what you are trying to do. However, from VFP, I created a simple project and program that might help you.
Start VFP. In the command window type
create project MyTest [enter]
click on the Code tab and then click new. Paste the following code snippet
LPARAMETERS DOSParm1, DOSParm2, DOSParm3, DOSParm4
MESSAGEBOX( "Parm1: " + TRANSFORM( DOSParm1 ) + CHR(13)+CHR(10);
+ "Parm2: " + TRANSFORM( DOSParm2 ) + CHR(13)+CHR(10);
+ "Parm3: " + TRANSFORM( DOSParm3 ) + CHR(13)+CHR(10);
+ "Parm4: " + TRANSFORM( DOSParm4 ) + CHR(13)+CHR(10) )
RETURN
Save the program as MyTest.prg, then click on build for the project to create an executable. Now you have a simple EXE file that accepts up to 4 parameters from the dos command or other methods (vbs). You can change the actual VFP to act on whatever variables you need, but I just have them as messagebox output display. If no parameters are provided, the default values would be logical .F. (false)
To test from a DOS prompt, you can do something like
MyTest oneParm anotherParm 3rd last
and you will get the message box displaying these 4 parameter strings.
If you skip parameters, no problem.
MyTest Only TwoParms
Again, the code can be changed to do whatever you need with your "2510" variable reference and act accordingly.

.PIF With ? Allowed for a Variable Request

Up until now I have been using the .PIF shortcut with "?" to call for a variable that is then used in a batch file to produce specific results. We have over project 10,000 folders, and the JobFind.PIF tool really satisfied a quick search. It is like a moving or floating Shortcut.LNK to any one folder in the larger directory.
Program Line Call Inside JobFind.PIF
S:\YoursTruly\JobFind\JobFind.bat ?
JobFind.bat Contents Where %1 = ?
explorer "P:\SDIT_L~1\Projects\000030%1"
Is there a simple replacement for my olde fashion JobFind.pif tool?
Thank you,
GPB
You could replace it with either a command-line or GUI VBScript. Here's an example:
strJob = InputBox("Enter the job number:")
With CreateObject("WScript.Shell")
.Run "explorer.exe P:\SDIT_L~1\Projects\000030" & strJob
End With

Batch or VBS | How to check the bitrate of a music file?

I need to check the bitrate of a music file, I need to receive the number in digits like: 192000 (for 192 kbps), 320000 (for 32kbps) or (+)3000000 for wavs and uncompressed music. I mean I need exactly the number, If an MP3 is VBR and is compressed at 194 kbps, I need the 194000 number, not the current CBR 192000.
I was do this job with MEDIAINFO (x64) CLI Program, In Batch:
for /f "tokens=*" %%%% in ('mediainfo "%%a" "--Inform=General;%%BitRate/String%%"') do set "BitRate=%%~%%"
But I have 35.000+ files to check and then the comprobation of all files is more than 2 hours of time.
I need a simple code to check it, Not a program which need to execute it and to waste that lot of time...
Is very important that the code needs to recognize at least this filetypes (I mean the internal bitrate):
AIFF, FLAC, M4A, MP3, OGG, WAV, WMA.
And can't be a code for Ruby or Python, because I'll need to "compile" it and sure when is "compiled" waste a lot of time to check much files (Cause the uncompression of the .exe compiled).
More info: I thinked about store the results in a file and then do a comparision to chek only new added files, But I can't store the result to do a comparision at the next run cause sometimes I'll need to replace checked files (old files). By the way neither I can't handle this by file datestamps. Need to be one unique procediment to check ALL the files, Ever (Or this is what I think...).
I tried another method to check the bitrates, I'm really sure this is what I need but I can't get it run like I want...
This VBS uses the DBPowerAmp program API, And shows a window with info (included the bitrate), But with a window I can't do nothing... Maybe if I can redirect the windows info to a text file... And then set the variable "Bitrate" by reading the bitrate info in the text file... But I don't know how to do that:
' create shell object
Set WshShell = CreateObject("WScript.Shell")
' Create dMC Object
Set dMC = CreateObject("dMCScripting.Converter")
'Read audio properties of a file
Dim AudioProps
AudioProps = dMC.AudioProperties("C:\test.aac")
Call WshShell.Popup(AudioProps, , "Returned Audio Properties", 0)
I've tried to "convert" that code into Batch, like this, But don't run, I get nothing:
#echo off
rundll32.exe dMCScripting.Converter.AudioProperties("C:\Test.aac") > test.txt
exit
Oh and I've tried this too, but waste more time than mediainfo:
mplayer "test.aac" -frames 0 | findstr "kbit"
To give you an idea of what it is like in Ruby, audioinfo is just one of the many libraries doing such things.
require "audioinfo"
AudioInfo.open("R:/mp3/j/John Coltrane - I Think.mp3") do |info|
puts info.to_h
end
=>{"artist"=>"John Coltrane", "album"=>"John Coltrane", "title"=>"I Think", "tracknum"=>nil, "date"=>nil, "length"=>272, "bitrate"=>128}
Here a vbs script, works with mp3, the rest i didn't try
Set objPlayer = CreateObject("WMPlayer.OCX" )
Set colMediaCollection = objPlayer.mediaCollection
Set colMedia = colMediaCollection.getAll()
For i = 0 to colMedia.Count - 1
Set objItem = colMedia.Item(i)
Wscript.Echo objItem.Name & " : " & objItem.GetItemInfo("bitrate")
Next
See http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/OLE~COM~ADO~CDO~ADSI~LDAP+Get~Audio~File~Information.txt for a list of attributes you can use.

Why does Applescript run in Script Editor, but error when saved as Application?

My applescript needs to detect its own filename, and the following runs fine on Snow Leopard (10.6)
set my_name to name of me as string
display dialog "Name: " & my_name
It displays "Name: AppleScript Editor" when I run it from AppleScript Editor, and it displays "Name: NewTest" when I save it as an application called NewTest.
When I run it on a Leopare (10.5) machine, it complains "Can't make name of <> into type string." When I remove the "as string" portion, it runs under Script Editor, returning "Name: Script Editor", but when saved as an application, it errors and says, "Can't get name."
What is different about running in script editor and saving as application under 10.5?
Here's another thought although I haven't checked. One thing that can cause problems is the command "get". In general when you run a command like "name of me" the command get is implied so you're really running "get name of me". The problem is that the implied "get" is not always the case. So sometimes you have to explicitly say "get". Whenever I have a problem like yours the first thing I try is to add "get" to the command... it's become habit because you just never know. Note that you can always use the word get and never have that issue. As such, try changing your command to "set my_name to (get name of me)". I'd be interested to know if that fixes your 10.5 problem. Also note that a name is already a string so there's no need to coerce the result to a string.
EDIT:
I looked through some of my older scripts. I used the following code to get the name. In my notes I have these comments...
-- this will get the name of the application or script without any file extension
-- it is done using the path because when a script is run from the script menu, and you write set myName to name of me, then the result is "applescript runner" instead of the actual name
-- also it assures that you're getting the name as it appears in the Finder because sometimes the system events process name is different than the Finder name
on getMyName()
set myPath to path to me as text
if myPath ends with ":" then
set n to -2
else
set n to -1
end if
set AppleScript's text item delimiters to ":"
set myName to text item n of myPath
if (myName contains ".") then
set AppleScript's text item delimiters to "."
set myName to text 1 thru text item -2 of myName
end if
set AppleScript's text item delimiters to ""
return myName
end getMyName
An Applescript application isn't an "application" in the truest sense of the word. A lot of contexts change, like "get path to me" will be different when run as a script or as an application, because they are still good ol' wonky Applescript as opposed to a Carbon or Cocoa-based application. Running similar code against the Finder...
tell application "Finder"
set my_name to name as string
display dialog "Finder: " & my_name
end tell
...behaves as expected because the Finder is a Carbon/Cocoa-based application.
I don't have a real answer other than to say it sounds like there was a change made to the OS relative to the Applescript framework in 10.6 that makes the call to "me" behave more as expected.
I would recommend reading the section in the Applescript guide about the me and it keywords to gain more insight into how me works.

Resources