Skip to content

Instantly share code, notes, and snippets.

@byBretema
Last active December 1, 2018 20:07
Show Gist options
  • Save byBretema/e7a4a2ef4e267b126d353ef19b494536 to your computer and use it in GitHub Desktop.
Save byBretema/e7a4a2ef4e267b126d353ef19b494536 to your computer and use it in GitHub Desktop.
Get 'carbon.now.sh' image on clipboard from the code that was previously on the clipboard :D
# CARBON-NOW-SH : 'npm i -g carbon-now-cli'.
# '-i' to setup your preset
# '-o' to open img on photos
# '--clear' remove all imgs from the folder
# '--path' open the path of imgs
function Carbon {
$path = "${env:LOCALAPPDATA}\CarbonNow\"
$file = "$path\carbon.data"
$imgName = $(Get-Date).Ticks
$imgPath = "$path\$imgName.png"
# Clear
if(($args[0] -eq "--clear") -or ($args[1] -eq "--clear")) {
Remove-Item "$path/*.png"
return
}
# Open path
if(($args[0] -eq "--path") -or ($args[1] -eq "--path")) {
Invoke-Item $path
return
}
# System files
if (-not(Test-Path $path)) { mkdir $path > $null }
Set-Content $file $(Get-Clipboard) > $null
# API call
if($args[0] -eq "-i") { carbon-now.cmd $file -i -l $path -t $imgName -h}
else { carbon-now.cmd $file -l $path -t $imgName > $null }
# Copy image to clipboard
[Reflection.Assembly]::LoadWithPartialName('System.Drawing') > $null
[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') > $null
if (Test-Path($imgPath)) {
$rawImg = [System.Drawing.Image]::Fromfile("$(Get-Item($imgPath))");
[System.Windows.Forms.Clipboard]::SetImage($rawImg);
} else { Write-Output "[NOT FOUND] --> $imgPath" }
# Maybe you wanna open the img to see it
if(($args[0] -eq "-o") -or ($args[1] -eq "-o")) {
Start-Process $imgPath
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment