Add time and date in custom/user Code Snippet in XCode

后端 未结 2 1126
灰色年华
灰色年华 2020-12-19 04:43

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

2条回答
  •  盖世英雄少女心
    2020-12-19 05:06

    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.

提交回复
热议问题