working on it ...
Explore Public Snippets
Found 1,210 snippets
public by snip2code modified Aug 13, 2017 598 4 4 0
First Snippet: How to play with Snip2Code
This is the first example of a snippet:
- the title represents in few words which is the exact issue the snippet resolves; it can be something like the name of a method;
- the description (this field) is an optional field where you can add interesting information regarding the snippet; something like the comment on the head of a method;
- the c
/* place here the actual content of your snippet. It should be code or pseudo-code. The less dependencies from external stuff, the better! */
public by JMichaelTX modified Feb 26, 2016 351549 2 3 0
AppleScript Trim Function / Handler Using ASObjC (Shane Stanley)
AppleScript Trim Function / Handler Using ASObjC (Shane Stanley):
trimThis Function AS.applescript
###BEGIN~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # trimThis() Trim (remove) Characters from Left and/or Right of String # # Ver 1.1 2016-02-25 # AUTHOR: Shane Stanley # (minor revisions by JMichaelTX) # REF: MacScripter / Trim [Remove Spaces] # http://macscripter.net/viewtopic.php?pid=182209#p182209 # PARAMETERS: # • pstrCharToTrim : A list of characters to trim, or true to use default # • pstrSourceText : The text to be trimmed # • pstrTrimDirection : Direction of Trim left, right or any value for full ###—————————————————————————————————————————————————————————————————————————————————— on trimThis(pstrSourceText, pstrCharToTrim, pstrTrimDirection) --- SET CHARACTERS TO TRIM --- if pstrCharToTrim = missing value or pstrCharToTrim = true then -- SPACE, TAB, RETURN, newline characters (U+000A–U+000D, U+0085) -- Equiv to: ASCII character 10, return, ASCII character 0 set setToTrim to current application's NSCharacterSet's whitespaceAndNewlineCharacterSet() else set setToTrim to current application's NSCharacterSet's characterSetWithCharactersInString:pstrCharToTrim end if set anNSString to current application's NSString's stringWithString:pstrSourceText --- TRIM STRING BASED ON REQUESTED DIRECTION --- if pstrTrimDirection = left then -- FROM LEFT SIDE OF STRING set theRange to anNSString's rangeOfCharacterFromSet:(setToTrim's invertedSet()) if |length| of theRange = 0 then return "" set anNSString to anNSString's substringFromIndex:(theRange's location) else if pstrTrimDirection = right then -- FROM RIGHT SIDE OF STRING set theRange to anNSString's rangeOfCharacterFromSet:(setToTrim's invertedSet()) options:(current application's NSBackwardsSearch) if |length| of theRange = 0 then return "" set anNSString to anNSString's substringToIndex:(theRange's location) else -- FROM BOTH SIDES OF STRING set anNSString to anNSString's stringByTrimmingCharactersInSet:setToTrim end if return anNSString as text end trimThis ###END~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public by JMichaelTX modified Feb 23, 2016 2069 1 3 0
Evernote Mac (EN Mac) Get and Sort Large List of Notes by Note Property using AppleScript and ASObjC.
Evernote Mac (EN Mac) Get and Sort Large List of Notes by Note Property using AppleScript and ASObjC.:
EN Mac Get & Sort Notes by Property AS.applescript
(* =============================================================================== [EN] Get and Sort Notes by Note Property Using "every note" Method & ASObJC [AS] =============================================================================== VER: 2.0 LAST UPDATE: 2016-02-22 PURPOSE: • Get and Sort Notes by Note Property Using "every note" Method & ASObJC • This script can handle very large list of Notes • Can get and sort 4,000 notes in less than 0.9 seconds. AUTHOR: JMichaelTX with a GIANT assist from @Shane Stanley and @hhas All errors are mine. Credit for the core approach and code goes to the above. Find any bugs/issues or have suggestions for improvement? Contact me via PM or at blog.jmichaeltx.com/contact/ REQUIRED: 1. Mac OS X Yosemite 10.10.5+ 2. Mac Applications • Evernote Mac 6.4+ 3. EXTERNAL OSAX Additions/LIBRARIES/FUNCTIONS • BridgePlus 1.3.1 Script Library by Shane Stanley https://www.macosxautomation.com/applescript/apps/BridgePlus.html 4. INTERNAL FUNCTIONS: • timer() Calculate and Log Execution Time (non-essential) • continueScript() Prompt User to Continue or Not REF: The following were essential in the writing of this script. 1. Using the "every note" method pointed out by @hhas at MacScripter.net http://macscripter.net/viewtopic.php?pid=184925#p184925 2. Using the ASOBjC sort facility in BridgePlus by Shane Stanley http://macscripter.net/viewtopic.php?pid=184936#p184936 =============================================================================== *) use AppleScript version "2.4" -- Yosemite 10.10.5+ use scripting additions use framework "Foundation" use BPLib : script "BridgePlus" load framework timer("start") --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- GET LISTS OF Evernote NOTE PROPERTIES TO SEARCH ON -- --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tell application "Evernote" set notebookStr to "MyBigNotebook" -- change to your Notebook tell every note in notebook notebookStr set titleList to its title set modDateList to its modification date -- will be main sort key in this example set noteLinkList to its note link -- will be used to get actual Note after sort end tell -- note set numNotes to count of noteLinkList log numNotes (* --- UNCOMMENT IF YOU'D LIKE A COMPARISION --- LOG RESULTS BEFORE SORT FOR COMPARISION --- log "~~~~~ BEFORE SORT ~~~~~~~" set indexList to 1 set modDate to item indexList of modDateList set noteLink to item indexList of noteLinkList set oNote to find note noteLink -- GET REF TO ACTUAL NOTE OBJECT set titleStr to title of oNote log "Mod Date: " & modDate & " Title: " & titleStr *) end tell -- Evernote timer("AFTER GET EN LISTS") --- CONFIRM CONTINUE WITH SCRIPT --- set msgStr to "Number of Notes to Process: " & numNotes if not (my continueScript(msgStr)) then error number -128 -- user canceled timer("start") -- restart timer after dialog --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- SORT EVERNOTE NOTE LISTS -- -- (requires BridgePlus Script Lib) --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- Convert Date List To Cocoa Format --- -- (Needed ONLY for Yosemite 10.10) set modDateList to Cocoaify modDateList -- needed for Yosemite 10.10 --- Setup the Sort --- set listPairs to BPLib's colsToRowsIn:{modDateList, noteLinkList} --- Do the Sort set listPairs to BPLib's sublistsIn:listPairs sortedByIndexes:{1, 2} ascending:{true} sortTypes:{} --- Get Sort Results --- set {modDateList, noteLinkList} to BPLib's colsToRowsIn:listPairs --- De-Cocoaify Date List For Yosemite 10.10 --- set modDateList to ASify from modDateList tell application "Evernote" log "~~~~~ AFTER SORT ~~~~~~~" set indexList to 1 -- should be oldest Note set modDate to item indexList of modDateList set noteLink to item indexList of noteLinkList set oNote to find note noteLink -- GET REF TO ACTUAL NOTE OBJECT set titleStr to title of oNote log "Mod Date: " & modDate & " Title: " & titleStr end tell -- Evernote timer("STOP") --~~~~~~~~~~~~~~~~~~~~~ END OF MAIN SCRIPT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ###—————————————————————————————————————————————— # continueScript() Prompt User to Continue or Not # # Ver 2.1 2016-02-21 ###—————————————————————————————————————————————— on continueScript(pMsgStr) beep set titleStr to (name of me) & " " & pMsgStr & " " & "Continue or Cancel?" set recAns to (display alert titleStr as critical ¬ buttons {"Cancel", "Continue"}) -- last button is default set strAns to button returned of recAns if (strAns = "Continue") then set continueBol to true else set continueBol to false end if return continueBol end continueScript ###—————————————————————————————————————————————— ###—————————————————————————————————————————————— # timer() Calculate and Log Execution Time # # Ver 1.0 2016-02-21 # # REF: The base ASObjC code was provided by Shane Stanley ###—————————————————————————————————————————————— on timer(pAction) (* ### Requires these two statements at top of main script: ### use scripting additions use framework "Foundation" *) global gTimerStartDate if (pAction = "start") then set gTimerStartDate to current application's NSDate's |date|() log "START: " & ((current date) as text) else log pAction & ": • " & ((current date) as text) & " • EXECUTION TIME: " & (round (-(gTimerStartDate's timeIntervalSinceNow())) * 1000) / 1000.0 & " sec" end if end timer
public by JMichaelTX modified Feb 13, 2016 2341 0 3 0
Evernote Mac Set Note Creation Date from Selection using AppleScript
Evernote Mac Set Note Creation Date from Selection using AppleScript:
EN Set Note Creation Date from Selection AS.applescript
(* ================================================================= SCRIPT NAME: Set EN CreationDate from Selection DATE: Thu, Jan 7, 2016 VER: 1.2 PURPOSE: • Set the EN Note Creation Date using text date which is selected • Expects the text date format to be in the form based on current Sys Pref settings • For USA: "Mon d, yyyy" or "m/d/yyyy" • Example: Jan 7, 2015 • OR to be in international date format, like "YYYY-MM-DD", where the dashes could be any character • I wrote this to automate the setting of Creation Date for the many web pages I clip, which most of the time were published on a prior date. AUTHOR: JMichael (member of Discussion.Evernote.com forum) Please PM me with any bugs/issues/questions INSTALLATION: • Copy to your personal Scripts folder: /Users/<YourName>/Library/Scripts/ (create the Scripts folder if it does not exist) HOW TO USE • Select a Note in Evernote • Select the text date in the Note you want to use for the Note Creation date • Click on the Apple Scripts menu in the upper right area of your menu • You can also use FastScripts (http://www.red-sweater.com/fastscripts/) to setup a KB shortcut. • Click on the name of this script: "Set EN CreationDate from Selection" • The script will use this selected date to set the Note Creation Date • A completion dialog window will be briefly show when completed METHOD: • Using the Clipboard • There is no specific AppleScript function to copy text from an app to the Clipboard • So, we have to rely on the "System Events" app to simulate a CMD-C • Once you have the text date on the CB, you have go "tell" an app like EN to set an AS variable to the CB. • Handling dates and strings can be a challenge in AppleScript • Couldn't find a general purpose text-to-date function that would handle all/most formats • So, the code below relies on the text date format being consistent with the date settings in the Mac Sys Prefs. • See the MacScripter ref below • Here are a few examples that will convert properly in the USA: date "12/25/04" date "12-25-04" date "12 25 04" date "dec 25 04" date "25 DEC 2004" -- with or without commas date "Dec 25, 2004" -- All compile to: date "Saturday, December 25, 2004 12:00:00 AM" • As of Ver 1.2, the international date format is accepted: "YYYY-MM-DD", where the dashes could be any character "2016-01-07", "2016/01/07", "2016.01.06" REF: 1. AppleScript: Handling Date & Time -- MacScripter, Jul 23, 2007 http://macscripter.net/viewtopic.php?id=24737 2. FastScripts -- http://www.red-sweater.com/fastscripts/ 3. Get selected text from any application http://macscripter.net/viewtopic.php?id=33575 ================================================================= *) property lsVer : "1.2" property strCreationDate : "Jan 7, 2016" set lsProcessTitle to "Evernote Set Creation Date " & lsVer (* ================================== COPY SELECTED TEXT TO CLIPBOARD • Evernote MUST be the active application • User MUST have selected TEXT in the Note --================================== *) activate application "Evernote" tell application "System Events" keystroke "c" using command down -- Simulate CMD-C end tell -- MUST BE IN EVERNOTE TO COPY FROM CLIPBOARD --- tell application "Evernote" set strCreationDate to (the clipboard as text) end tell --display dialog strCreationDate --========================================== -- CONVERT TO DATE OBJECT --========================================== -- MUST NOT BE IN ANY APP WHEN USING THE date FUNCTION -- try -- Try Standard U.S. date format -- set dCreationDate to date (strCreationDate) on error --- Try International Date format (YYYY-MM-DD) set dCreationDate to convertIntlDate(strCreationDate) end try --display dialog "Date Object: " & dCreationDate --========================================== -- SET EN COMPLETION DATE --========================================== tell application "Evernote" set _sel to selection -- Gets the Note(s) Selected in Evernote if _sel ≠ {} then set aNote to first item of _sel -- Get ONLY the 1st Note set creation date of aNote to dCreationDate else display dialog "*** NOTE NOT SELECTED ***" end if end tell beep display notification ("Note Created Date set to: " & dCreationDate) with title lsProcessTitle --======================= END OF MAIN SCRIPT ================ to convertIntlDate(textDate) --- textDate MUST be in the format of YYYY<delim>MM<delim>DD --- where <delim> can be any character --- like 2016-01-05 set resultDate to the current date set the year of resultDate to (text 1 thru 4 of textDate) set the month of resultDate to (text 6 thru 7 of textDate) set the day of resultDate to (text 9 thru 10 of textDate) set the time of resultDate to 0 if (length of textDate) > 10 then set the hours of resultDate to (text 12 thru 13 of textDate) set the minutes of resultDate to (text 15 thru 16 of textDate) if (length of textDate) > 16 then set the seconds of resultDate to (text 18 thru 19 of textDate) end if end if return resultDate end convertIntlDate (* ===== END OF: Set EN CreationDate from Selection ===== *)
public by JMichaelTX modified Feb 11, 2016 187948 0 3 0
Set Keyboard Maestro (KM) Variable using AppleScript
Set Keyboard Maestro (KM) Variable using AppleScript:
Set KM Variable Function AS.applescript
###—————————————————————————————————————————————— # setKMVar() Sets KM Variable, Makes if needed # # Ver 2.0 2015-12-27 ###—————————————————————————————————————————————— on setKMVar(pKMVarName, pKMVarValue) --log ("setKMVar: " & pKMVarName & ": " & pKMVarValue) tell application "Keyboard Maestro Engine" try -- to set variable, will error if it doesn't exist set value of variable pKMVarName to pKMVarValue on error -- Make & Set Variable make new variable with properties {name:pKMVarName, value:pKMVarValue} end try end tell -- KM end setKMVar
public by JMichaelTX modified Feb 9, 2016 2728 0 3 0
Evernote Mac Create File (.inetloc) Using Note Classic Link with AppleScript
Evernote Mac Create File (.inetloc) Using Note Classic Link with AppleScript:
EN Create Note Link as File AS.applescript
(* =============================================================================== [EN] Create Note Link as File =============================================================================== VER: 2.0 LAST UPDATE: 2016-02-08 PURPOSE: • Create a File (web location) Using the Evernote Classic Note Link AUTHOR: JMichaelTX Find any bugs/issues or have suggestions for improvement? Contact me via PM or at blog.jmichaeltx.com/contact/ REQUIRED: 1. Mac OS X Yosemite 10.10.5+ 2. Mac Applications • EN Mac 6+ 4. INTERNAL FUNCTIONS: • createWebLocFile() REF: The following were used in some way in the writing of this script. (1) http://blog.nik.me/post/44311282771/create-a-desktop-shortcut-to-an-evernote-note (2) https://discussion.evernote.com/topic/37457-sharing-evernote-to-devonthink/?p=208821 =============================================================================== *) tell application "Evernote" set lstSelectedNotes to selection if lstSelectedNotes ≠ {} then set oNote to first item of lstSelectedNotes set strNoteTitle to title of oNote set strNoteLink to note link of oNote my createWebLocFile(strNoteLink, strNoteTitle) end if end tell -- Evernote --~~~~~~~~~~~~~~~~~~~~~~ END OF MAIN SCRIPT ~~~~~~~~~~~~~~~~ ###—————————————————————————————————————————————— # createWebLocFile() Create File with Hyperlink # # Ver 2.0 2016-02-08 ###—————————————————————————————————————————————— on createWebLocFile(pstrNoteLink, pstrNoteTitle) set strPrompt to "For Note: " & pstrNoteTitle set aliFolder to choose folder with prompt strPrompt tell application "Finder" set aliFile to make new internet location file to pstrNoteLink at (aliFolder) with properties {name:pstrNoteTitle} --- OPEN FINDER SHOWING FILE --- reveal aliFile end tell -- application "Finder" end createWebLocFile
public by JMichaelTX modified Jan 24, 2016 200420 1 3 0
[EN] Classic - Evernote Mac - Put Classic Note Link on Clipboard as Rich Text using Note Title -- AppleScript
[EN] Classic - Evernote Mac - Put Classic Note Link on Clipboard as Rich Text using Note Title -- AppleScript:
Copy EN Note Link (Classic) AS.scpt
(* SCRIPT NAME: Copy EN Note Link (Classic) DATE: Sat, Jan 23, 2016 VER: 2.1.1 PURPOSE: • Get Classic link of selected Evernote Note • Copy to Mac Clipboard as RTF (Rich Text Format) so that you can paste to most apps as a click-able link • Text is EN Note Title • Link is the "Classic", internal link to EN Mac Note AUTHOR: JMichaelTX (member of Discussion.Evernote.com forum) Please PM me with any bugs/issues/questions REQUIRES: • Satimage.osax for HTML encode (encode entities) (Free D/L & info at http://tinyurl.com/Satimage-Osax-DL ) INSTALLATION: • There are several ways you can install and access this script • SIMPLE METHOD • Copy to your personal Scripts folder: /Users/<YourName>/Library/Scripts/ (create the Scripts folder if it does not exist) • Select a Note in Evernote • Click on the Apple Scripts menu in the upper right area of your menu • Click on Copy EN Note Link (classic) • Switch to your target app, and click in the text area where you want the link, and press CMD-V • OTHER OPTIONS • FastScripts -- http://www.red-sweater.com/fastscripts/ • Automator • See article on Veritrope.com for details: http://veritrope.com/tech/the-basics-using-keyboard-shortcuts-with-applescripts/ REF: • I was inspired by: • This thread on Discussion.Evernote.com forum: https://discussion.evernote.com/topic/60623-how-can-make-the-classic-link-the-default-way-of-linking/ • Post by patnpm https://discussion.evernote.com/topic/60623-how-can-make-the-classic-link-the-default-way-of-linking/#entry283106 • Post by DanielB https://discussion.evernote.com/topic/60623-how-can-make-the-classic-link-the-default-way-of-linking/#entry291008 • I adapted the code posted by: • alastor933 in the MacScripter.com forum • http://macscripter.net/viewtopic.php?pid=148647#p148647 ====================================================================== *) property bolDebug : false -- set to true to turn on diagnostic logs and dialogs. -- SET THE BELOW PROPERTIES TO REFLECT THE LINK STYLE YOU WANT --- property gstrFont : "font-family:verdana,geneva,sans-serif;" property gstrLinkFontSize : "font-size:14px;" property gStyleLink : "color:blue" tell application "Evernote" set lstSelectedNotes to selection if lstSelectedNotes ≠ {} then --- GET THE FIRST NOTE --- set oNote to first item of lstSelectedNotes --- GET THE NOTE TITLE AND CLASSIC NOTE LINK --- set strNoteTitle to title of oNote set strNoteLink to note link of oNote log strNoteTitle set strNewTitle to "" --- REPLACE EXTENDED ASCII CHARS BETWEEN 127-253 WITH SPACE -- repeat with iChar from 1 to (length of strNoteTitle) set strChar to character iChar of strNoteTitle --set strLog to ("[" & iChar & "] " & (ASCII number of strChar) & ": " & strChar) --log strLog if ((ASCII number of strChar) > 126) and ((ASCII number of strChar) < 254) then set strNewTitle to strNewTitle & " " else set strNewTitle to strNewTitle & strChar end if end repeat ## --- ENCODE THE NOTE TITLE --- ## -- (requires the Satimage.osax) set strNoteTitle to encode entities strNewTitle log strNoteTitle --- CREATE THE HTML ANCHOR CODE --- set strHTMLLink to my createHTMLLink(strNoteTitle, strNoteLink) set strHTMLLink to "<span style=\"" & gstrFont & gstrLinkFontSize & "\">" & strHTMLLink & "</span>" --- PUT THE HTML CODE ON THE CLIPBOARD AS RICH TEXT (RTF) --- my copyHTMLasRTFtoClipboard(strHTMLLink) set strMsg to strNewTitle set strMTitle to "Evernote Internal Link Copied to Clipboard for" display notification strMsg with title strMTitle sound name "Hero.aiff" end if -- lstSelectedNotes ≠ {} end tell --===================================== -- SUBPROGRAMS --===================================== ###—————————————————————————————————————————————— # Create HTML Link: createHTMLLink ###—————————————————————————————————————————————— on createHTMLLink(pstrLinkText, pstrURL) return "<a href=\"" & pstrURL & "\" style=\"" & gStyleLink & "\">" & pstrLinkText & "<a>" end createHTMLLink ###—————————————————————————————————————————————— # COPY HTML TO CLIPBOARD AS RTF: copyHTMLasRTFtoClipboard ###—————————————————————————————————————————————— on copyHTMLasRTFtoClipboard(pstrHTML) if bolDebug then display dialog "ENTER copyHTMLasRTFtoClipboard" -- REWRITTEN AS RTF AND COPIED TO THE CLIPBOARD set lstrCMD to "echo " & quoted form of pstrHTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf" do shell script lstrCMD if bolDebug then display notification pstrHTML with title "Copy RTF to Clipboard" end if end copyHTMLasRTFtoClipboard
public by JMichaelTX modified Jan 22, 2016 2174 0 3 0
Evernote AppleScript to Set author property of Selected Notes (AS)
Evernote AppleScript to Set author property of Selected Notes (AS):
(EN) Set Author of Selected Notes AS.scpt
(* =============================================================================== Set Author of Selected Notes =============================================================================== VER: 1.0 LAST UPDATE: 2016-01-21 PURPOSE: • Set the Author field in all selected Notes AUTHOR: JMichaelTX Find any bugs/issues or have suggestions for improvement? Contact me via PM or at blog.jmichaeltx.com/contact/ REQUIRED: 1. Mac OS X Yosemite 10.10.5+ 2. Mac Applications • Evernote 3. INTERNAL FUNCTIONS: • continueScript(pMsgStr) • getUserAns(pMsgStr) COMMENTS • The "author" property is NOT shown as a property of the Notes object in the Evernote Scripting Dictionary. • However, testing revealed that it is available. =============================================================================== *) --------------------------- tell application "Evernote" ------------------------- set notesList to selection set iNumNotes to count of notesList log ("Number of Notes to Process: " & iNumNotes) if (not my continueScript("Number of Notes in Selection: " & iNumNotes)) then return set newAuthorStr to my getUserAns("Enter Author for Selected Notes") log ("*** New Author: " & newAuthorStr & " ***") log ("START: " & ((current date) as text)) set iNote to 0 ------------------------------- repeat with oNote in notesList ----------------------------- set iNote to iNote + 1 set titleStr to title of oNote log ("[" & iNote & "]: title: " & titleStr) set author of oNote to newAuthorStr end repeat -- oNote end tell -- Evernote --------------------------- log ("END: " & ((current date) as text)) --~~~~~~~~~~~~~~~~~~~~~~~~~~ END OF MAIN SCRIPT ~~~~~~~~~~~~~~~~~~~~~~~ ###————————————————————————————————————————————————————————————————————— # continueScript() Confirm Running of Script # # Ver 1.0 2016-01-21 ###————————————————————————————————————————————————————————————————————— on continueScript(pMsgStr) --–––––––––––––––––––––––––––––– beep set ansRec to (display alert "Continue or Cancel?" message pMsgStr as critical ¬ buttons {"Cancel", "Continue"}) -- last button is default set strAns to button returned of ansRec if (strAns = "Continue") then set continueBol to true else set continueBol to false end if return continueBol end continueScript --—————————————————————————————————————————————————————————————————————— ###————————————————————————————————————————————————————————————————————— # getUserAns() Get Users Input # # Ver 1.0 2016-01-21 ###————————————————————————————————————————————————————————————————————— on getUserAns(pMsgStr) --–––––––––––––––––––––––––––––– beep set ansRec to (display dialog pMsgStr ¬ with title (name of me) ¬ with icon caution ¬ default answer "") set ansStr to text returned of ansRec return ansStr end getUserAns --——————————————————————————————————————————————————————————————————————
public by JMichaelTX modified Jan 14, 2016 1925 0 3 0
DEMO & Functions for Real Progress Bar using ASObjC in AppleScript
DEMO & Functions for Real Progress Bar using ASObjC in AppleScript:
ASObjC Progress Bar AS.scpt
(* ============================================================================== PURPOSE: Show how to display real Progress Bar using ASObjC Runner app • Redesigned to use FUNCTIONS VER: 1.1.2 DATE: Mon, May 18, 2015 AUTHOR: JMichaelTX Please post comment any bugs/issues/questions or suggestions for improvement • All of the credit for this functionality goes to Shane Stanley, who wrote the ASObjC Runner app, and many other incredible ASObjC apps and libraries • My only real contribution is in putting this in functions REF: http://www.macosxautomation.com/applescript/apps/runner_vanilla.html REQUIRES: 1. Mac OS X Mavericks, or later 2. ASObjC Runner app 2. ProgressBar Functions (included below) 1. initProgressBar(psTitle, psMsg, piMax, piCurrent) 2. updateProgressBar(piCurrent, piMax) 3. closeProgressBar() The ASObjC Runner app may be downloaded from: http://www.macosxautomation.com/applescript/apps/ASObjC_Runner.zip Previously, there was no good way to show a standard progress bar from AppleScript. Yosemite adds a Progress Bar to AppleScript, but for Mavericks there was no good solution until ASObjC Runner. This script provides a demo of the ASObjC Runner Progress Bar. I adapted the demo code from MacOSXAutomation.com to use Functions. The progress window property is used to set the properties of the progress window you can display. You can set the window's name, whether it includes a button and its title, the message and detail, as well as various properties related to the progress bar. As of version 1.9.2, you can optionally have it display a second progress bar. Typically you set these properties before showing the progress window, and update them as your task proceeds. There are three commands related to the progress window: reset progress will reset all the relevant properties to their default values, show progress will display the window, and hide progress will close the window. Typically you issue the reset command, set the various progress window properties to suit, show the window, update it as your script progresses, then hide it. Here is a basic example. As of version 1.9.2, you can show two progress bars. ============================================================================== *) set sPBStatus to "TBD" -- Will be set to "Cancel" if User Cancels. Otherwise set to "OK" --- VARIABLES TO BE SET IN YOUR SCRIPT --- set sPBTitle to "ASObjC Runner Progress Bar" -- Window Title set sPBMsg to "DEMO Progress Bar by ASObjC Runner" -- Msg ABOVE progress bar --- FOR DEMO ONLY --- set iStart to 1 set iEnd to 100 --------------------------------------------- -- *** INITIALIZE PROGRESS BAR *** my initProgressBar(sPBTitle, sPBMsg, iEnd, 0) --- REPLACE with your own REPEAT LOOP --- repeat with iCurrent from iStart to iEnd -- *** UPDATE PROGRESS BAR JUST BEFORE YOUR PROCESSING *** set sPBStatus to my updateProgressBar(iCurrent, iEnd) -- HANDLE CANCEL BY USER -- if (sPBStatus = "Cancel") then exit repeat end if --- INSERT YOUR PROCESSING HERE -- delay 0.1 -- for demo only, not needed in production use end repeat -- *** CLOSE PROGRESS BAR *** my closeProgressBar() --- HANDLE ANY CLEANUP IF USER CANCELED --- if (sPBStatus = "Cancel") then display notification ("User CANCELED process") with title sPBTitle -- YOUR CODE HERE -- else display notification ("Process SUCCESSFULLY Completed") with title sPBTitle end if -- User Canceled --——————— END OF MAIN SCRIPT —————————————————————————————— --———————————————————————————————— -- SUBPROGRAMS --———————————————————————————————— --———————————————————————————————— on initProgressBar(psTitle, psMsg, piMax, piCurrent) (* PURPOSE: Initialize the ASObjC Runner Progress Bar VER: 1.1 DATE: Mon, May 18, 2015 AUTHOR: JMichael (on Discussion.Evernote.com site) REF: http://www.macosxautomation.com/applescript/apps/runner_vanilla.html *) -- NOTE: The "name" and "message" properties need to be set only here. -- They will continue to show when the UPDATE is called -- without being included in the properties there. tell application "ASObjC Runner" -- set up dialog and show it reset progress set properties of progress window to ¬ {button title:"Cancel", button visible:true, name:psTitle, message:psMsg, detail:"", indeterminate:false, max value:piMax, current value:piCurrent} activate show progress end tell delay 0.5 end initProgressBar --——————————————————————————————— --———————————————————————————————— on updateProgressBar(piCurrent, piMax) (* PURPOSE: UPDATE the ASObjC Runner Progress Bar VER: 1.1.1 DATE: Mon, May 18, 2015 AUTHOR: JMichael (on Discussion.Evernote.com site) REF: http://www.macosxautomation.com/applescript/apps/runner_vanilla.html *) tell application "ASObjC Runner" -- By NOT activating the app during the update call, allows user to work in other apps --activate set properties of progress window to ¬ {detail:"This is number " & piCurrent & " of " & piMax, current value:piCurrent} if button was pressed of progress window then --exit repeat return "Cancel" end if end tell return "OK" end updateProgressBar --———————————————————————————————— --———————————————————————————————— on closeProgressBar() (* PURPOSE: HIDE the ASObjC Runner Progress Bar VER: 1.1 .2 DATE: Mon, May 18, 2015 AUTHOR: JMichael (on Discussion.Evernote.com site) REF: http://www.macosxautomation.com/applescript/apps/runner_vanilla.html *) tell application "ASObjC Runner" to hide progress end closeProgressBar --———————————————————————————————
public by marksimon232 modified Jul 6, 2015 3522 2 6 0
Swift: .max and .min properties
If you have code around that uses lots of F’s (e.g. 0xFFFFFFFF) or capital letters (e.g. UINT32_MAX), consider replacing these constants with built-in Swift versions.
Swift offers .max and .min properties for many numeric types. For example: public func Random01() -> Double { return Double(arc4random()) / Double(UInt32.max) }