How can I add date time in my custom code snippet?
I need frequent use to add my codes on other codes, and for others, I need to add my name and date time.
I created a code snippet with shortcut _ase, but I am not finding any help on net how can I add time to it.
You can't add date or time automatically using the native Xcode snippet grammar.
Snippets do not have anything other than token substitution using the <#VisibleTokenName#> syntax.
File templates are generated differently and have token substitution for a small subset of predefined tokens (like ___DATE___) in addition to the ability for custom tokens gathered in the UI.
You could write a bash script (or whatever) to update the snippet file for you with the correct date.
Looks like you can't do this using XCode snippets but I can suggest a quick workaround using apple script:
set str to "// Created by Anoop Vaidya on " & (do shell script "date '+%d/%m/%Y'")
tell application "Xcode"
activate
set the clipboard to (str as text)
tell application "System Events"
keystroke "v" using command down
end tell
end tell
You can set date using apple script:
set str to ("// Created by Anoop Vaidya on " & day of (current date) & "/" & ((month of (current date)) as integer) as string) & "/" & year of (current date)
but it is not so convenient as using shell script.
Now you need only to bind that script to some shortcut (using FastScripts for example) and use it.
You can add some additional functionality to the script like saving previous value from clipboard and then restoring it or may be just using some XCode scripting properties to directly insert text without clipboard.
Related
I am building an energy system model that is using a combination of VBA and Python (Pyomo). I am using a small piece of VBA code to call a command line, which in turn uses Pyomo. This code is looping to execute a separate Pyomo optimisation for each day.
The code is working perfectly, apart from the message in the image below being triggered. When I step through the code slowly, the message seems to be triggered by the following line of code which is calling a command line:
Call Shell("cmd.exe /S /c" & "pyomo solve --solver=glpk " & Pyomo_file & " " & DAT_file & " --save-results " & Results_file, vbHide)
I have also tried to run this with the string being simplified down into a single string variable, which I called "Command", but the message below was still triggered.
The hyperlink in the message box (https://support.microsoft.com/en-us/office/malicious-macros-were-found-9e461c61-69d1-4ea9-a386-9ad0deaccfdd?ns=excel&version=90&syslcid=1033&uilcid=1033&appver=zxl900&helpid=56779&ui=en-us&rs=en-us&ad=us) suggests that this issue is triggered by AMSI and that my computer thinks this code is malicious. It is not - it is doing exactly what I want it to!! Digging further I think (but may be wrong) that the virus checks are being triggered by the fact that this string is a combination of so many inputs - the virus checker thinks this is obfuscation.
A few further points:
This line of code is within the daily loop I mentioned above. The
error does not get triggered until the loop has already happily
executed this line >30 times.
Bizarrely it seems to get thrown out on
the same date each time I try to run the loop. If I skip that date, it falls over again at a later date...
I have set my macro security settings to "enable all macros" and this
still happens. I only have the one Office 365 licence in my
organisation (my own company) so I don't think there can be any odd admin
permissions causing this problem.
Finally, I have tried to define the folders I am using as 'safe locations' and this doesn't help either.
Ideally, I would like to just disable the AMSI software while this command line is being executed. But I don't know how to do this of whether it is even possible. If not, any alternative ideas?!
I tried to run the MpCmdRun.exe script suggested by MS in this post, and it seems to have worked. It's possible that is just fluke, but it is working for now! Fingers crossed!
I am trying to tie together a filemaker script that will export PDFs to a temporary space and use and apple script to print them.
I was able to cull together info from this and some other boards to create an applescript that will print the PDFs using Acrobat from a folder.
I have already created a script that finds the Related attachments and exports them to the desktop.
What I'm having trouble with is merging the two.
I need to export the PDF to a folder or temporary place and trigger the apple script to initiate the printing...
This great Suggestion was provided by Chuck of chivalrysoftware.com/…...
Calculate the location to export by appending the filename to Get( TemporaryPath ).
Export the container field contents to FileMaker to that path.
Save the path to a global field in FileMaker
Use an embedded AppleScript to access the global field path
Use AppleScript to open the file in Preview and print it
This is my apple script:
set myFolder to (path to desktop folder as text) & "Print:"
set myfiles to list folder myFolder without invisibles
repeat with myfile in myfiles
set mycurrentfile to ((myFolder as string) & (myfile as string)) as string
batchprint(mycurrentfile)
end repeat
on batchprint(mycurrentfile)
tell application "Adobe Acrobat Pro"
activate -- bring up acrobat
open alias mycurrentfile -- acrobat opens that new file
tell application "System Events"
tell process "Acrobat"
click menu item "Print..." of menu 1 of menu bar item "File"¬
of menu bar 1
click button "Print" of window "Print"
tell application "System Events"
tell process "Acrobat"
click menu item "Close" of menu 1 of menu bar item "File"¬
of menu bar 1
end tell
end tell
end tell
end tell
end tell
tell application "Finder" -- to move the printed file out
set x to ((path to desktop folder as text) & "Printed PDFs:")
if alias x exists then
beep
else
make new folder at the desktop with properties {name:"Printed PDFs"}
end if
move alias mycurrentfile to folder "Printed PDFs"
end tell
end batchprint
My Filemaker script is:
Go to Related Record[
Show only related records; From table: 'Attachments";
Using layout: "Attachements Report' (Attachments); New window
]
Enter Find Mode
Constrain Found Set [Restore]
Sort Records [Restore; No dialog]
# After finding the related attachments and constraining them to the specific type
# we rename and export them to the desktop
Go to Record/Request/Page [First]
Loop
Set Variable [$Path; Value:
Get ( DesktopPath ) & Attachments::Record number & "-"
& Attachment Type List 2::Prefix_z & Lien::Lien_ID_z1]
Export Field Contents [Attachments::file_c; $Path]
Go to Record/Request/Page [Next: Exit after last]
End Loop
Close Window [Current Window]
First of all, the FileMaker part. Create a global text field in one of your tables. It looks like the Attachments table would be the best place for it. I'll call it g_applescript_parameter for this.
Now we're going to use your $Path variable, which given the calc you've provided should be something like /Aslan/Users/chuck/Desktop/1234-ABC4321. I'd recommend appending a .pdf to the end of it since you'll be exporting PDF files. This may help later.
Also, I would recommend that you use Get( TemporaryPath ) instead of Get( DesktopPath ). Anything you place in the temporary folder will be automatically deleted when you quit FileMaker, which means you don't have to write anything to clean up the desktop folder later and you don't have to manually trash them either. Let FileMaker do that work for you. :)
Regardless, FileMaker uses a path of the form filemac:/volumeName/directoryName/fileName (see the notes in the Specify output file dialog box for the Export Field Contents script step). So you should also prepend filemac: to the beginning of your path variable.
All told, your $Path should be set to something like this:
"filemac:" & Get( DesktopPath ) & Attachments::Record number & "-" &
Attachment Type List 2::Prefix_z & Lien::Lien_ID_z1 & ".pdf"
So your export path for FileMaker should work better now. But AppleScript requires a different format for the path to the same file. Given the above, AppleScript's version should be something like /Users/chuck/Desktop/1234-ABC4321.pdf. In other words, everything after the drive name. Fortunately FileMaker can get the drive name with the Get( SystemDrive ) function. For me that function returns /Aslan/. So if we take the $Path variable as defined above and remove filemac: and the name of the drive as defined by Get( SystemDrive ) and add an extra slash at the beginning, that would convert our FileMaker path into an AppleScript path:
"/" & Substitute( $Path; "filemac:" & Get( SystemDrive ); "" )
Use Set Variable to create an $ASPath variable and set it to the above.
Now within your loop store the contents of the $ASPath variable within that global text field:
Loop
Set Variable[ $Path; …]
Set Variable[ $ASPath; …]
Set Field[Attachments::g_applescript_parameter; $ASPath)
Export Field Contents[Attachments::file_c; $Path]
Go to Record/Request/Page[Next; Exit after last]
End Loop
Now AppleScript can extract that information. I'm assuming that given an accurate file being passed to the batchprint function, batchprint will work, so keep that, but remove everything before it and use something like this:
set _pdf_path to contents of cell "g_applescript_parameter" of current layout
batchprint(_pdf_path)
on batchprint(mycurrentfile)
...
end batchprint
Add a Perform AppleScript step after the Export Field Contents step and place the above code in it.
Note that the first line of the above AppleScript will only work as written from within FileMaker. If you're testing this outside of FileMaker in, for example, Script Editor, then you'll need to make that first line read
tell applicaiton "FileMaker" to set _pdf_path ...
You don't need to do this within the Perform AppleScript script step because by default commands are sent to the enclosing FileMaker application.
We've got an applescript that tells keynotes to delete slides based on criteria. The new keynote does not have an applescript dictionary, but leaves the old keynote in a subdirectory. So I'm trying to tell AppleScript to talk with the older app rather than the new one.
If I just
tell application "Clean Install:Applications:iWork '09:Keynote.app"
It works, but it doesn't recognize any of the keynote dictionary terms. (delete a slide). So I need to pull out my old friend "using terms from". The challenge here is that this is a precompile directive, so you have to use a string literal, which I don't have on the end user's machine due to different hard drive names.
Ok, still have a plan here. I will write out a new applescript file with the 'using terms from application "Clean Install:Applications:iWork '09:Keynote.app"' and then execute that file... Genius... except for the fact that when AppleScript compiles this line:
using terms from application "Clean Install:Applications:iWork '09:Keynote.app"
Gets changed to:
using terms from application "Keynote"
Which of course calls the new keynote's dictionary which is empty.
Any thoughts on how to keep applescript from helping me out in this way? (or is there a better plan?)
full code:
using terms from application "Clean Install:Applications:iWork '09:Keynote.app"
--using terms from application "Clean Install:Applications:iWork '09:Keynote.app"
tell application "Clean Install:Applications:iWork '09:Keynote.app"
activate
end tell
end using terms from
many thanks!
I'm flyin' blind here (don't have keynote) ... but have you tried using a pre-defined app string as a variable and raw event codes?
You can use Smile to easily get raw event codes by
making a new script window in Smile;
using the "tell" menu item from the Action menu to make that script window application-specific (no tell
block needed);
write a line of code; select line of code
then use the "Copy translate" menu item (cmd-shift-C)
to copy the raw event codes
pasting that raw event code code into a different window that has your working (normal tell block) script
This is what it looks like when I do this for the Mail app:
set origMail to "MyDrive:Applications:Mail.app"
tell application origMail
delete («class mssg» 1 of «class mbxp» "INBOX" of «class mact» 1)
end tell
( When put in a normal tell block, that line of code would be "delete (message 1 of mailbox "INBOX" of account 1)" )
I haven't tried this but I think it will work... when you compile your code with "using terms from" just place your new version of Keynote in the trash. That should force it to use the old version of Keynote's dictionary and your code should compile. If you then save that code as an "applescript application" then it should work on anybody's computer without need to recompile. NOTE: you may need to restart your computer before this trick would work.
Then you just have the problem of targeting the right application on the user's computer because they too might have both versions. Here's some code to find the path to older versions of Keynote and how you would target that.
set lsregister to "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"
set appName to "Keynote.app"
set nonapplescriptVersion to "6.0"
-- get the path to all Keynote apps
set appPaths to paragraphs of (do shell script lsregister & " -dump | grep " & quoted form of appName)
-- find the one with a version number less than the nonapplescriptVersion of Keynote
set appPath to missing value
repeat with anApp in appPaths
try
-- extract the path
set AppleScript's text item delimiters to "/"
set tis to text items of anApp
set thisPath to "/" & (items 2 thru end of tis) as text
set AppleScript's text item delimiters to ""
-- check the version
if (version of application thisPath) is less than nonapplescriptVersion then
set appPath to thisPath
exit repeat
end if
end try
end repeat
if appPath is missing value then error "Needed application version not installed."
-- use the older version
using terms from application "Keynote"
tell application appPath
activate
-- do whatever
end tell
end using terms from
A two-part question but they tie in together. - I'm experimenting with VB.net console applications and I'm wandering how I send command line commands to the console window. Take the below Sub.
Sub initialLoad()
Console.WriteLine("Started # " + %date% %time%)
Console.WriteLine("Test")
End Sub
I'm trying to add the equivalent of echo. which would add a line break, I tried using the string Console.WriteLine("Test", vbCrLf) but the vbCrLF made no difference and did not add a line break after the text.
The %date% and %time% variables when used on a Batch script for example will give the current date and time and is recognised and defined automatically within the CMD window. Am I able to send these CMD commands to the console or must I use VB.net equivalents to achieve this.
I found that instead of pause>nul I had to use Console.ReadLine() to make the console window pause.
Am I incorrect in assuming I can use CMD commands? I know in C++ I can send all the commands but is there something similar in VB.net? Thanks.
For environment variables use Environment.GetEnvironmentVariable
For new line use Environment.NewLine
For commands see here: How To: Execute command line in C#, get STD OUT results - this is in C# but you can use the same objects in VB.NET.
I just started to study Visual Basic .NET. I would like to build a dynamic system log text box.
When program is passing one point of code or function, a textbox in another form is updating with the system log.
For example, when the program starts, it appends "System start" to the textbox in another form. When the program starts to use the "cal" function, then the program appends "System: start to cal data" on the textbox in another form.
However, I am not really sure how to update this system log dynamically. Do I need to use threading? Can I do it without threading? Can anyone give me an example?
To add to Mertis's suggestion, what you can do is to fire a code which concatenates details to your textbox whenever an object is called/code is executed
for example, a function was executed:
Function sampleFunc()
.....
Textbox1.text = Textbox1.Text & vbnewline & DateTime.Now & _
" a Function was Executed"
End Function
Note that I added a datetimenow, in case you needed time details.